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]

当我访问此 URL 时:http: //mysite.com/user/john/ - 这完全可以正常工作!但是当我在最后没有斜杠的情况下访问 URL 时,如下所示:http://mysite.com/user/john浏览器告诉我这个错误:

在此处输入图像描述

我应该在这里做什么?您的帮助将不胜感激和奖励!

谢谢!:-)

4

1 回答 1

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 处理。

于 2012-08-13T03:22:43.133 回答