当前位置: 动力学知识库 > 问答 > 编程问答 >

php - MOD_REWRITE but not in sub directories

问题描述:

I have the following HTACCESS code:

Options +FollowSymLinks

RewriteEngine On

RewriteBase /

#RewriteCond %{REQUEST_URI} !(/cms/|/js/|/mobile/)* [NC]

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.*)$ /page.php [L]

As it stands, it works as I need it to within the root of the site, but accessing an admin page (/cms/), I can tell via PhpConsole that it is still hitting page.php. I think this is because the admin is controlled with a query string: URIs look like /cms/?view=pages&action=edit&id=4

If I uncomment the first condition, this problem no longer occurs, but my front end comes back with a 404 on files that don't exist, rather than redirecting to page.php

What is wrong with my code?

网友答案:

Change your code with this:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule (?!^(cms|js|mobile)(/.*|)$)^.*$ page.php [L,NC]
分享给朋友:
您可能感兴趣的文章:
随机阅读: