.htaccess在最后没有删除我的网址" Not Found"

时间:2012-08-13 03:17:24

标签: .htaccess url url-rewriting

#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浏览器告诉我这个错误:

enter image description here

我该怎么办?非常感谢您的帮助和奖励!

谢谢! : - )

1 个答案:

答案 0 :(得分: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处理。