除了已经声明的其他重写之外的所有RewriteRule

时间:2013-10-01 01:36:51

标签: apache .htaccess

我使用.htaccess(例如)

将以下条目作为固定文件处理
RewriteEngine On    
RewriteRule ^redir$ redir_base64.php
RewriteRule ^confirm$ confirm.php
RewriteRule ^migrate$ migrate.php
RewriteRule ^import_conn$ import_conn.php
RewriteRule ^callback_ot$ callback_ot.php
RewriteRule ^callback_yh$ callback_yh.php
RewriteRule ^callback_gp$ callback_gp.php
RewriteRule ^callback_lk$ callback_lk.php
RewriteRule ^results/map$ index.php
RewriteRule ^results$ index.php
RewriteRule ^robots\.txt$ robots.php
RewriteRule ^sitemap\.xml$ sitemap.php
RewriteRule ^removeml$ removeml.php
RewriteRule ^rss$ rss_gen.php
RewriteRule ^cpt\.jpg$ c/captcha/captcha.php
RewriteRule ^cptfrm\.jpg$ c/captcha/captcha.php?width=120&height=60&characters=4
RewriteRule ^cptfrm160\.jpg$ c/captcha/captcha.php?width=100&height=60&characters=3
RewriteRule ^login/lk$ login_conn.php?op=lk
RewriteRule ^t$ c/thumb/phpThumb.php
RewriteRule ^spce$ spce.php
RewriteRule ^orplkd$ order_publisher.php
RewriteRule ^ord_ren$ order_reactivate.php
RewriteRule ^logout$ logout.php

此条目正常!但是我需要访问/ 000/000,我发现与线条的冲突表明如下。

RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([\d\w\-\.]+)/([\d]+)$ index.php [QSA,L]
RewriteRule ^([\d\w\-\.]+)$ index.php [QSA,L]

我尝试使用该行访问我的网站,但我无法识别最后一行,因为在网站上使用所有访问权限。

我希望能理解我的帮助。

谢谢!

1 个答案:

答案 0 :(得分:1)

您需要重复2个条件。重写条件适用于紧接着的条件。

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\d\w\-\.]+)/([\d]+)$ index.php [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\d\w\-\.]+)$ index.php [QSA,L]