我有这个非常基本的重写规则,无论我尝试什么,都会导致错误500.
RewriteEngine On
RewriteRule ^folder/(.*) /folder/index.php?Alias=$1 [L]
我的httpd.conf文件包含以下内容:(对我来说似乎没问题)
<Directory "/var/www/html">
Options -Indexes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
<IfModule mod_suphp.c>
suPHP_Engine On
suPHP_UserGroup webapps webapps
SetEnv PHP_INI_SCAN_DIR
</IfModule>
</Directory>
有关可能出现的问题的任何建议?我还尝试在重写规则的末尾添加$
。
答案 0 :(得分:1)
重写引擎将重复循环,直到URI停止更改,或者达到内部重定向限制,这会导致引发500错误。您的规则的目标URI /folder/index.php
将被重新引入重写引擎,并且您的相同规则的正则表达式与^folder/(.*)
匹配。因此,您需要添加某种条件以防止循环。
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/folder/index\.php
RewriteRule ^folder/(.*) /folder/index.php?Alias=$1 [L]
这很简单,如果它已经以/folder/index\.php
开头,它就不会应用该规则。您也可以尝试:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^folder/(.*) /folder/index.php?Alias=$1 [L]
这对条件的限制要少一些。如果请求的URI未映射到现有文件或目录,它仅应用规则。这假设当您尝试转到/folder/blahblah
时,不是目录或文件blahblah
,并且您希望通过index.php路由它。