English 中文(简体)
htaccess RewriteCond, Multi Conditions for Rewrite Rule
原标题:htaccess RewriteCond, Multiple Conditions for RewriteRule

I use .htaccess Mod Rewrite to send the URL to index.php, which then parses the URL and builds each page of my website. This works perfectly fine, allowing me to easily manage clean URLs using PHP instead of .htaccess.

参看。 -> go to index.php, whichload a page with multi PHP file setjoint

然而,I m试图允许某些PHP文件作为普通PHP文件装上(没有将URL发送到分区)。

Ex: http://domain.com/some/url/here/ still works as mentioned above. http://domain.com/specialexception.php will load as a regular php file, without sending to index.php

我有以下法典:

<IfModule mod_rewrite.c>

    RewriteEngine On

    RewriteCond $1 !^specialexception.php$ [NC]
    RewriteRule !.(css|gif|jpg|png|ico|txt|xml|js|pdf|htm|zip)$ /path/to/index.php [NC,L]

</IfModule>

然而,现在完全无视RewriteCond行。

我感谢任何帮助/帮助。

谢谢。

最佳回答

我不敢肯定为什么这样做:

I switched the rules around so they happened in reverse order. Code that works is as follows:

RewriteCond %{REQUEST_URI} !.(css|gif|jpg|png|ico|txt|xml|js|pdf|htm|zip)$
RewriteRule !(specialexception)+.php)$ /path/to/index.php [NC,L]

The problem with this solution: Since "specialexception.php" is listed as the last rule, in the actual RewriteRule line, it only solves the problem for ONE file exception.

环绕的一条重要途径可能是将管道用于最后一条管线:

RewriteCond %{REQUEST_URI} !.(css|gif|jpg|png|ico|txt|xml|js|pdf|htm|zip)$
RewriteRule !(specialexception|anotherexception|foo|bar)+.php)$ /path/to/index.php [NC,L]

If anyone has a better idea on how to add multiple exceptions for multiple files, I d love to know!

问题回答
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !(specialexception).php$
    RewriteCond %{REQUEST_URI} !(anotherexception).php$
    RewriteRule !.(css|gif|jpg|png|ico|txt|xml|js|pdf|htm|zip)$ index.php [NC,L]
</IfModule>

这对我来说是罚款的。 如果您的入学情况与指数相同。 php没有使用我们手法的道路。 相反,使用与您的“htaccess-file”相对的道路。





相关问题
Ignore symlinks in clean URL s in .htaccess

Example URL: example.com/user /user is both a symlinked directory and a valid URL to content on my site. I user Horde Routes to request the content and all requests to the site go through index.php. ...

.htaccess File Options -Indexes on Subdirectories

I have the following .htaccess line, simple no indexes on root. Options -Indexes What do we add so it propagates to any sub directory instead of having to create one file for each? One .htaccess on ...

Mod Rewrite ignoring -d

After a day or two, I am still fighting with Mod Rewrite. It seems that 60% of my development time is spent battling the server. My current URL structure is such that all http://example.com/xyz and ...

ErrorDocument 404 Not Sending Referrer Information: PHP

I m using a standard htaccess ErrorDocument 404 to redirect users to a new page. In order to customize the 404, I need to know their referrer information (from the page they Tried to visit). $...

Find all htaccess files on server [closed]

I m looking for a Linux command to go through all the directories on my server and find all .htaccess files. The output would be a list of all those files with full path, creation/modification date ...

301 Redirect Help with Dynamic URL s and Multiple Id s

I just did a redesign for www.wildchildclothes.com which has a new URL structure. The old site ran on Zen Cart and had a bad URL structure. Here are some examples of what I want to redirect from: OLD:...

热门标签