使用mod_rewrite可以同时去除PHP扩展和干净的GET网址干净、网址、mod_rewrite、PHP

2023-09-02 00:50:04 作者:过渡客.

这是我试过至今:

  RewriteEngine叙述上

的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME -f .PHP
重写规则(。*)$ 1.PHP [L]

的RewriteCond%{QUERY_STRING} ^ n =([0-9] {1})$
重写规则^文章 .PHP $ /条/%1 [L]
 

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

第二组规则是应该更换任何有article.php?编号= NUM​​BER在其插入/条/数

阿帕奇报道:

  AH00124:请求超过了10内部重定向的限制,由于有可能
配置错误。使用'LimitInternalRecursion'如果有必要提高限制。
 
如何开启mod rewrite功能

解决方案

第二组规则应该更换任何有article.php?ID =数成/条/数字。

我相信你有逆转的规则。

试试这个code来代替:

  RewriteEngine叙述上
的RewriteBase / mellori /

#外部重定向从实际的URL pretty的1
的RewriteCond%{} THE_REQUEST /article.php?id=([^s&]+)[NC]
重写规则^文章/%​​1? [R = 302,L]

#内部重写/条/ 123 article.php?ID = 123
重写规则^文章/([0-9] +)$ article.php?ID = $ 1 [L,NC,QSA]

#PHP隐藏规则
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME -f .PHP
重写规则^(。*)$ $ 1.PHP [L]
 

This is what I've tried till now:

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]

Basically, the first set of rules converts the URLs from something.php to something.

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

Apache reports:

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

解决方案

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

I believe you have rules reversed.

Try this code instead:

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]