这就是我需要的。我有url pearlsquirrel.com/profilecomments.php?u=eggo。 eggo是我的用户名和动态网址的一部分。我想用.htaccess重写url来说明pearlsquirrel.com/eggo/comments。
这是我到目前为止所做的:
RewriteRule ^(.*)$ $1.php
RewriteRule ^([a-zA-Z0-9_-]+)$ profilecomments.php?u=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profilecomments.php?u=$1
RewriteCond %{HTTP_HOST} ^www\.pearlsquirrel\.com$ [NC]
RewriteRule ^(.*)$ http://pearlsquirrel.com/$1/comments [L,R=301]
但我无法让它发挥作用。任何帮助将不胜感激。谢谢!
答案 0 :(得分:1)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/comments$ profilecomments.php?u=$1 [L]
注意强>
如果您已经为图像,样式表等使用了相对路径,则需要使用服务器根文件夹作为基础将这些路径更改为绝对路径或相对路径,以使您的站点正常显示。
例如,它会认为images/image.png
是/eggo/comments/images/image.png
但是,如果您改为添加前面的斜杠/images/image.png
,您的文件路径将始终从服务器根文件夹开始,并且当您重写URL时,您的网站不会搞砸。
答案 1 :(得分:0)
你的第一条规则将覆盖所有其他规则。 您所描述的内容(如果我理解正确),您需要通过profilecomments.php处理/ user / comments?u = user
RewriteRule ^([a-zA-Z0-9_-]+)/comments profilecomments.php?u=$1 [L]
这应该这样做。