我有一个索引页面www.domainname.com和一个名为all.php的文件。 我想通过.htaccess文件动态更改它。 我想从www.yourame.com/all.php?category=foo 到www.yourname.com/all/foo 到目前为止我在.htaccess中尝试过的是
RewriteEngine On
RewriteRule ^(.*)/index.php/?category=$1 [QSA]
但结果在url中仍然相同。
www.yourname.com/all.php?category=foo
所以我怎样才能达到预期的效果,提前谢谢
答案 0 :(得分:2)
您可以在DOCUMENT_ROOT/.htaccess
文件中使用此代码:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /all\.php\?category=([^\s&]+) [NC]
RewriteRule ^ all/%1? [R=302,L,NE]
RewriteRule ^all/([^/.]+)/?$ all.php?category=$1 [L,QSA,NC]
答案 1 :(得分:0)
我相信您遇到的问题是因为您在重写和文件路径之间缺少空格。
这样的事可能适合你:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.php?category=$1 [QSA]
答案 2 :(得分:0)
尝试此规则
RewriteRule ^all/([A-Za-z0-9-]+)/?$ all.php?category=$1 [NC,L]
答案 3 :(得分:0)
你试过这个,它的作用就像一个冠军 我的.htaccess文件代码是
RewriteEngine On
RewriteRule ^all/([^/.]+) all.php?category=$1 [L,NC]
我的索引文件代码是
<a href="all/foo>click here</a>
,结果是
www.yourdomain.com/all/foo