htaccess正在重写地址栏



我一直在尝试更改我的URL,使其对SEO更友好目前已经设法让他们我想要它。

我的原始网址是:http://www.example.com/index.php?keyword=nikon

因此,设法进行了重写,使其现在看起来像这样:

http://www.example.com/compare/nikon.html

使用此:

RewriteEngine On
RewriteRule ^compare/([^/]*).html$ /index.php?keyword=$1 [R,NC,L]

但我试图得到最终结果,以便地址栏中的url是这样的:http://www.example.com/compare/nikon.html

如果我更改它,使重写的url在地址栏中仍然会传递变量,并且在存在锚点#标记的实例中url之后它还能工作吗?

感谢您的帮助

您希望在规则中去掉R标志。这导致地址栏被更改为原来难看的URL。

此外,如果你想将浏览器从难看的URL重定向到好看的URL,你需要一个不同的规则。所以类似于:

RewriteEngine On
RewriteCond %{THE_REQUEST}  /+index.php?keyword=([^& ]+)
RewriteRule ^ /compare/%1.html? [L,R]
RewriteRule ^compare/([^/]*).html$ /index.php?keyword=$1 [NC,L]

最新更新