我正在尝试将https://www.exapmle.com/profile.php?u=8
看起来像https://www.exapmle.com/profile/8
我在htaccess
:
RewriteRule ^/profile/([0-9]+)/?$ profile.php?u=$1
RewriteRule ^/profile/([0-9]+)\.html /profile.php?u=$1
我不知道我做错了什么,链接没有改变,我也没有收到任何错误
答案 0 :(得分:0)
您可以在站点根目录中使用此代码.htaccess:
Options -MultiViews
RewriteEngine On
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /profile\.php\?id=([^\s&]+) [NC]
RewriteRule ^ /profile/%1? [R=301,L]
# internal forward from pretty URL to actual one
RewriteRule ^/?profile/(\d+)(?:\.html)?/?$ profile.php?u=$1 [L,QSA,NC]