0

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. 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.

Now when I go to mysite.com/pp/test.php (that file does exist), it redirects to 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:

    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
dmikester1
  • 1,374
  • 11
  • 55
  • 113
  • 1
    Refer to this link [link](https://stackoverflow.com/questions/3414015/redirect-site-with-htaccess-but-exclude-one-folder) – Gopi Feb 11 '19 at 05:20
  • I actually saw that link in my search. Adding `!^pp($|/)` after either of my `RewriteRule` commands produces an internal server error. – dmikester1 Feb 11 '19 at 05:25
  • try changing the permissions of the folder causing the internal server error – Peace Feb 11 '19 at 05:59

1 Answers1

0

Just below RewriteEngine On line add this to skip pp/ and everything under this folder:

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
anubhava
  • 761,203
  • 64
  • 569
  • 643