“漂亮链接”的重写规则无效

时间:2018-05-24 22:00:05

标签: .htaccess

我正在尝试将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

我不知道我做错了什么,链接没有改变,我也没有收到任何错误

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]