[英]Rewrite rule for clean url
我正在尝试为我的网站上的个人资料写一个干净的URL。 例如,我想要这个网址
/profile?user=MrEasyBB
成为
/MrEasyBB
我当前的htaccess
就是这样开始的
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ profile.php?user=$1 [NC,L]
DirectoryIndex index.php
如果我是正确的,这一切都应该起作用。 但是,如果说的是他们键入的页面网址,会说什么呢?
/help
不应有一个名为help
的用户,并且页面应直接指向help.php
。 我可以写一条不遵循特定模式的规则吗? 我还想知道更改图像,评论等的规则:
IE
/image/user/MrEasyBB/1239123871712194124.jpg
代替
/image/picture.php?user=MrEasyBB&image=1239123871712194124.jpg
对于第一个无效的重写规则以及如何执行第二个规则的重写规则,我对如何添加倍数和遵循模式不满意?
我还下载了htaccess
备忘单pdf,以了解更多信息
您首先需要有一个规则来重写图像以更正路径,然后将出现“全部捕获”规则:
DirectoryIndex index.php
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^(image)/[^/]+/(.+)$ /$1/$2 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^user/(.+)$ profile.php?user=$1 [NC,L,QSA]
就像是:
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?image/user/([a-zA-Z0-9_-]+)/([a-zA-Z0-9.]+)$ /image/picture.php?user=$1&image=$2 [NC,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ profile.php?user=$1 [NC,L]
DirectoryIndex index.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.