7

这是我到目前为止所尝试的:

RewriteEngine On

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

RewriteCond %{QUERY_STRING} ^id=([0-9]{1})$
RewriteRule ^article\.php$ /article/%1 [L]

基本上,第一组规则将 URL 从 something.php 转换为 something。

第二组规则应该将其中包含 article.php?id=NUMBER 的任何内容替换为 /article/NUMBER。

阿帕奇报告:

AH00124: Request exceeded the limit of 10 internal redirects due to probable 
configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary.
4

2 回答 2

2

The second set of rules is supposed to replace anything that has article.php?id=NUMBER in it into /article/NUMBER.

我相信你的规则颠倒了。

试试这个代码:

RewriteEngine On
RewriteBase /mellori/

# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /article\.php\?id=([^\s&]+) [NC]
RewriteRule ^ article/%1? [R=302,L]

# internally rewrites /article/123 to article.php?id=123
RewriteRule ^article/([0-9]+)$ article.php?id=$1 [L,NC,QSA]

# PHP hiding rule
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
于 2013-11-11T19:28:49.340 回答
0

您需要确保匹配时^article\.php$它来自实际请求,而不是由先前规则重写的 URI。因此,您可以为内部重定向附加 ENV 检查,或匹配`%{THE_REQUEST}。

你的选择:

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^id=([0-9]{1})$
RewriteRule ^article\.php$ /article/%1 [L]

或者

RewriteCond %{THE_REQUEST} \ /+article\.php\?id=([0-9]{1})(\ |$)
RewriteRule ^ /article/%1 [L]
于 2013-11-08T06:29:05.450 回答