URL 在 .htaccess 上重写
URL Rewrite On .htaccess
我正在尝试制定一个可以理解的重写规则
作为
http://example.com/test.php?t=1234
这是我现在拥有的,但它不起作用:
RewriteEngine on
RewriteRule ^test?t=([^/\.]+)/?$ http://mywebsite.com/test/ [L]
有人可以帮帮我吗?
你的 rewriteRule 是倒退的,因为你应该在左边匹配你想要干净的 url 的样子,并在右边重写到文件在服务器上的位置。但即使它不是向后的,您也必须转义 RegExp 中的问号字符。但是因为它是倒退的,你应该使用更接近于:
的东西
RewriteEngine on
RewriteRule ^test/(.*) test.php?t= [L]
尝试:
RewriteEngine On
RewriteCond %{THE_REQUEST} /test.php\?t=([^&\s]+) [NC]
RewriteRule ^test.php$ /test/%1? [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test/([^/]+)/?$ /test.php?t= [QSA,L,NC]
查询字符串不是重写规则指令中匹配的一部分,请使用 %{QUERY_STRING} 或 %{THE_REQUEST} 变量来匹配查询字符串。
我正在尝试制定一个可以理解的重写规则
作为
http://example.com/test.php?t=1234
这是我现在拥有的,但它不起作用:
RewriteEngine on
RewriteRule ^test?t=([^/\.]+)/?$ http://mywebsite.com/test/ [L]
有人可以帮帮我吗?
你的 rewriteRule 是倒退的,因为你应该在左边匹配你想要干净的 url 的样子,并在右边重写到文件在服务器上的位置。但即使它不是向后的,您也必须转义 RegExp 中的问号字符。但是因为它是倒退的,你应该使用更接近于:
的东西RewriteEngine on
RewriteRule ^test/(.*) test.php?t= [L]
尝试:
RewriteEngine On
RewriteCond %{THE_REQUEST} /test.php\?t=([^&\s]+) [NC]
RewriteRule ^test.php$ /test/%1? [NC,R,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test/([^/]+)/?$ /test.php?t= [QSA,L,NC]
查询字符串不是重写规则指令中匹配的一部分,请使用 %{QUERY_STRING} 或 %{THE_REQUEST} 变量来匹配查询字符串。