简体   繁体   English

htaccess-将除了文件夹和特定文件以外的所有内容重定向到index.php

[英]htaccess - redirect everything to index.php except a folder and specific files

I have been fighting with this for way too long. 我为此战斗了太久了。 I have a my PHP site hosted with a .htaccess file for rewriting and redirecting. 我的PHP网站托管有.htaccess文件,用于重写和重定向。 It has been working great so far. 到目前为止,它一直运行良好。 Now I simply want to add a subfolder, /pp that everything inside it does not get redirected or rewritten, basically it should not get touched by my .htaccess stuff. 现在我只想添加一个子文件夹/pp ,它里面的所有内容都不会被重定向或重写,基本上,我的.htaccess东西应该不会碰它。

Now when I go to mysite.com/pp/test.php (that file does exist), it redirects to mysite.com/index 现在,当我转到mysite.com/pp/test.php(该文件确实存在)时,它将重定向到mysite.com/index

Here is what I currently have: 这是我目前拥有的:

RewriteEngine On

#remove www for all traffic
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

#prevent redirect of submit
RewriteRule ^/?submit$ submit.php [L]

#prevent redirect of paypal
RewriteRule ^/?admin$ admin.php [L]
RewriteRule ^/?testPPButton$ testPPButton.php [L]

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/pp/.* [NC]  // this line is not working for some reason
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Options -Indexes

Updated .htaccess: 更新的.htaccess:

    RewriteEngine On

# skip /pp/* from all rules below
RewriteRule ^pp(/.*)?$ - [L,NC]

#remove www for all traffic
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

#prevent redirect of submit
RewriteRule ^/?submit$ submit.php [L]

#prevent redirect of paypal
RewriteRule ^/?admin$ admin.php [L]
RewriteRule ^/?testPPButton$ testPPButton.php [L]

# browser requests PHP
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

# check to see if the request is for a PHP file:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Options -Indexes

Just below RewriteEngine On line add this to skip pp/ and everything under this folder: RewriteEngine On在线下面,添加此代码以跳过pp/以及此文件夹下的所有内容:

RewriteEngine On

# skip /pp/* from all rules below
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\s/+pp[/?\s] [NC]
RewriteRule ^ - [L,NC]

# rest of your rules go below this

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM