我在将 /authentication/view_profile?user=(username) 重写为 myurl.com/profil/(username) 时遇到问题
现在我的 .htaccess 文件是:
RewriteEngine On
#Rewrite /view.php?vis=id to /opslag/vis/id
#RewriteRule ^opslag/vis/(\d+)$ /opslag/view.php?vis=$1 [NC,QSA,L]
#Rewrite authentication/view_profile.php?user=* to profil/*
RewriteRule ^profil/(\d+)$ /authentication/view_profile.php?user=$1 [NC,QSA,L]
#Remove index.php
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
RewriteRule ^(.*)index\.php$ /$1 [R=301,L]
#Remove /page/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L]
我已经在使用一条规则重写另一个规则,即“#Rewrite view.php?vis=id to /opslag/vis/id
现在我的网址如下所示:
<a href='/profil/$_SESSION[username]'>Vis profil</a>
我希望你愿意帮助我。
如果您需要一些详细信息,请告诉我..:o)
改用这个:
RewriteRule ^profil/([^/]+)$ /authentication/view_profile.php?user=$1 [NC,QSA,L]
您的规则只能接受仅包含数字的用户名(\d+)
。这个([^/]+)
将接受任何字符(除了/
,这是文件夹分隔符)。
P.S.考虑阅读这篇文章正则表达式和 mod_rewrite 简介 http://httpd.apache.org/docs/current/rewrite/intro.html如果您计划定期使用 .htaccess 和 URL 重写规则。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)