我有如下的htaccess行:-
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [NC,L]
RewriteRule ^articles/images/(.*)$ images/$1
RewriteRule ^articles/(.*)/images/(.*)$ images/$2
RewriteRule ^articles/([a-zA-Z0-9_-]+)$ articles.php?articleType=$1
RewriteRule ^articles/([a-zA-Z0-9_-]+)/([0-9]+)$ articles.php?articleType=$1&page=$2
RewriteRule ^articles/([a-zA-Z0-9_-]+)/(.*)$ articles.php?articleType=$1&articleID=$2
问题是如果我评论RewriteRule ^(.*)$ $1.php [NC,L]
,则可以显示http://localhost/trip/articles/Sightseeing
。但我无法显示http://localhost/trip/privacy
(错误:找不到对象!)。如果取消注释该行,则可以显示http://localhost/trip/privacy
,但不能显示http://localhost/trip/articles/Sightseeing
(错误:内部服务器错误)。
我已经尝试插入<Directory /> AllowOverride All </Directory>
,但出现错误:服务器错误!并插入<IfModule mod_rewrite.c>...</IfModule>
,得到错误:内部服务器错误。
有什么方法可以成功显示这两个链接吗?提前谢谢。
我已经解决了。对于那些和我有同样问题的人:-
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ $1.php
RewriteRule ^articles/images/(.*)$ images/$1
RewriteRule ^articles/(.*)/images/(.*)$ images/$2
RewriteRule ^articles/([a-zA-Z0-9_-]+)$ articles.php?articleType=$1 [L]
RewriteRule ^articles/([a-zA-Z0-9_-]+)/([0-9]+)$ articles.php?articleType=$1&page=$2
RewriteRule ^articles/([a-zA-Z0-9_-]+)/(.*)$ articles.php?articleType=$1&articleID=$2