使用mod_rewrite可以同时去除PHP扩展和干净的GET网址 [英] Use mod_rewrite to remove .php extension and clean GET urls concurrently

查看:175
本文介绍了使用mod_rewrite可以同时去除PHP扩展和干净的GET网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我试过至今:

  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'如果有必要提高限制。
 

解决方案

第二组规则应该更换任何有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]

这篇关于使用mod_rewrite可以同时去除PHP扩展和干净的GET网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆