.htaccess
。URLs
。我想要:
demo.example.com/section.php?id=1
变成:
demo.example.com/section/sample-section
我试过了
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^section/(\d+)*$ ./section.php?id=$1
但没有区别
谢谢。
感谢您的帮助。
首先,确保mod_rewrite的被启用和htaccess的文件允许在你的Apache配置。
然后,将此代码放入您的htaccess中(必须位于根文件夹中)
Options -MultiViews
RewriteEngine On
# redirect "/section.php?id=xxx" to "/section/xxx"
RewriteCond %{THE_REQUEST} \s/section\.php\?id=([0-9]+)\s [NC]
RewriteRule ^ /section/%1? [R=301,L]
# internally rewrite "/section/xxx" to "/section.php?id=xxx"
RewriteRule ^section/([0-9]+)$ /section.php?id=$1 [L]
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句