2012-08-13 85 views
1
#RewriteEngine On 

#RewriteCond %{REQUEST_FILENAME} !-d 
#RewriteCond %{REQUEST_FILENAME}\.php -f 
#RewriteRule ^(.*)$ $1.php 

RewriteEngine On 
RewriteBase/

# Use the following rule if you want to make the page like a directory 
RewriteRule ^user/(!(profile.php))$ user/$1/ [R=301,L] 

# The following rule does the rewrite. 
RewriteRule ^user/(.+)/$ profile.php?id=$1 

# The following rewrite the other way round: 
RewriteCond %{REQUEST_URI} ^/profile.php 
RewriteCond %{THE_REQUEST} ^(GET|POST|HEAD|TRACE)\ /profile.php 
RewriteCond %{QUERY_STRING} id=([^&]+) 
RewriteRule ^profile.php$ user/%1? 

<files .htaccess> 
order allow,deny 
deny from all 
</files> 

RewriteCond %{HTTP_HOST} ^www\.mysite\.com$ 
RewriteRule ^(.*)$ "http\:\/\/mysite\.com\/$1" [R=301,L] 

当我访问此网址: http://mysite.com/user/john/ - 这完全完美的作品! 但是,当我存取权限的URL没有斜杠结尾,就像这样:http://mysite.com/user/john浏览器告诉我这个错误:的.htaccess做我的网址结尾没有斜杠“未找到”

enter image description here

我应该怎么做吗?您的帮助将不胜感激,并获得奖励!

谢谢! :-)

回答

1

您的规则在这里:

RewriteRule ^user/(!(profile.php))$ user/$1/ [R=301,L] 

似乎并没有对我的工作。尝试将其更改为:

RewriteCond %{REQUEST_URI} !^/user/profile.php 
RewriteRule ^user/(.*[^/])$ user/$1/ [R=301,L] 

因为你原来的规则不匹配,对于http://mysite.com/user/john请求是通过规则打滑不变,因此不会通过profile.php处理。

+0

所以你在这里做的是强制URL在最后有一个斜杠,对吧? :) – PinoyStackOverflower 2012-08-13 03:30:20

+0

@ElsonSolano是的,它看起来像你原来的规则是试图做到这一点,而你的重写规则'RewriteRule^user /(.+)/$ profile.php?id = $ 1'特别与尾部的斜线匹配,所以没有它,没有任何反应。 – 2012-08-13 03:36:54

相关问题