1

I have .htacces like this:

ErrorDocument 404 /error/404.php

Options +FollowSymlinks

RewriteEngine On

RewriteRule articles/(.*)-(.*) articles.php?$2=$1
RewriteRule download/(.*) download.php?q=$1

#add extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule (.*) $1.php [L]

Now, my problem is: on localhost it works fine, but on server (mod_rewrite is enabled, checked), it throws 500 error. Any ideas?

4

2 回答 2

1

像这样拥有完整的 .htaccess:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^articles/([^-]+)-(.*)$ articles.php?$2=$1 [L,QSA,NC]
RewriteRule ^download/(.*)$ download.php?q=$1 [L,QSA,NC]

# To internally forward /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^(.+?)/?$ $1.php [L]
于 2013-09-07T18:35:48.537 回答
0

观察你的 apache 错误日志。你会注意到重写的数量越来越多.php。问题是,如果该文件不存在,它将继续添加.php,直到它因“内部重写太多”而出错。您需要排除.php请求中已经存在扩展的所有情况:

#add extension
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule (.*) $1.php [L]

为了使您的最后一条规则在其他规则上正常工作,您也需要[L]其他规则的标志。这将使 apache.htaccess再次使用变量中的正确信息进行检查。

RewriteRule articles/(.*)-(.*) articles.php?$2=$1 [L]
RewriteRule download/(.*) download.php?q=$1 [L]
于 2013-09-07T18:25:46.747 回答