用RewriteRule更改url不会替换url并重定向我的页面


Changing url with RewriteRule does not replace the url and redirects my page

我正在尝试以下mod_rewrite代码更改我的网站的url到一个不同的,但似乎如果它是重定向,我希望页面加载我的目标url。

假设我想加载url: www.AAAAAA.com/store/index.php?categ=cars但在URL栏我想显示以下内容: www.AAAAAA.com/store/cars

我的代码是这样的(但不工作,因为它重定向和重写不正确):

RewriteEngine On
RewriteRule ^store/(.*)$ store/index.php?categ=$1 [L]

谢谢你的建议!

试试下面的代码:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}'s/+(store)/index'.php'?categ=([^'s]+) [NC]
RewriteRule ^ /%1/%2? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f    
RewriteRule ^store/(.+?)/?$ /store/index.php?categ=$1 [L,QSA,NC]

一旦您确认它工作正常,将R=302替换为R=301。在测试mod_rewrite规则时避免使用R=301(永久重定向)

试试这个:

Options -Multiviews
RewriteEngine on
RewriteRule ^(store/images|store/css|store/js)($|/) - [L]
RewriteBase /store/
RewriteRule ^store/(.*)$  index.php?categ=$1 [QSA,L]

您可以使用第3行来排除重写的任何目录,例如,您不希望重写domain.com/store/images/logo.jpg的请求