.htaccess 如何使用htaccess文件从url隐藏id =

zkure5ic  于 2022-11-25  发布在  其他
关注(0)|答案(2)|浏览(144)

我需要的网址

localhost/project/category?c=electronics

localhost/project/category/electronics

我试过了

RewriteRule ^category/([^/\.]+)?$ /category.php?c=$1  [L]
RewriteRule ^category/+?$ /category.php?c=$1  [NC,L]
p8h8hvxi

p8h8hvxi1#

请尝试以下htaccess规则测试您的示例和尝试。请在测试URL之前清除浏览器缓存。

RewriteEngine ON
RewriteBase /
##External redirect to url change in browser.
RewriteCond %{THE_REQUEST} \s/(project/category)\.php\?c=(\S+)\s [NC]
RewriteRule ^ /%1/%2? [R=301,L]

##Internal rewrite to category.php in backend.
RewriteCond %{DOCUMENT_ROOT}/$1/$2.php -f
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ %{DOCUMENT_ROOT}/$1/$2.php?c=$3 [QSA,L]
yfjy0ee7

yfjy0ee72#

RewriteEngine on
RewriteBase /

RewriteRule ^project/category/([0-9a-z]+)$ /project/category?c=$1 [L]

为什么在最初的尝试中缺少“project/”?
您必须指定完整的路径。您可以尝试这个简单的rewriteRule,它应该会起作用。

相关问题