Wordpress in root. PHP in subdirectory. htaccess help?

3 replies
I have a site with Wordpress in the root folder.

I have a subfolder called /directory/

The /directory folder has all PHP files that are not associated with Wordpress at all.

I have my directory working fine when I don't place a .htaccess file in the directory folder. So for instance, /directory/states.php?country=usa shows up and operates just fine. I created an htaccess folder hoping I could rewrite this to /directory/usa...

/directory/states.php?country=usa -> /directory/usa

I simply used this in my .htaccess file WITHIN my /directory folder:
--------------------------
RewriteEngine On

RewriteCond %{REQUEST_URI} ^/directory/
RewriteRule ^(.*) /directory/index.php [L]

RewriteCond %{REQUEST_URI} ^/directory/([a-z0-9,\_]+)
RewriteRule ^(.*) /directory/states.php?country=%1 [L]
---------------------------

This breaks all pages and gives the infamous "Internal Server Error" page.

Thoughts? How do I do this? I've done this several times on a site that didn't have Wordpress in the root. But now the wordpress .htaccess seems to be screwing it up or something.

Thanks in advance!
#htaccess #php #root #subdirectory #wordpress
  • Profile picture of the author kokopelli
    The main root .htaccess file will also affect any subdirectories under it, because .htaccess files follow a hierarchy from top to bottom.

    You can try removing the .htaccess file from /directory/ and adding its directives to your main (WordPress) .htaccess file, before the WordPress directives, like so:
    Code:
    <IfModule mod_rewrite.c>
    RewriteEngine On
    
    RewriteCond %{REQUEST_URI} ^/directory/
    RewriteRule ^(.*) /directory/index.php [L]
    
    RewriteCond %{REQUEST_URI} ^/directory/([a-z0-9,_]+)
    RewriteRule ^(.*) /directory/states.php?country=%1 [L]
    </IfModule>
    
    # BEGIN WordPress
    BTW I haven't checked the above directives, just stating the principle.

    Hope it works! (If not, try just adding the /directory/ directives before the WordPress directives, without the <IfModule mod_rewrite.c> and </IfModule>
    Signature
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    {{ DiscussionBoard.errors[5478097].message }}
  • Profile picture of the author rknuppel
    Thanks a ton for the quick reply. No such luck though. Tried all combinations as stated above. I wonder if my directives are just wrong in general? Any other thoughts anyone?
    {{ DiscussionBoard.errors[5478125].message }}
  • Profile picture of the author kokopelli
    You could turn off mod_rewrite for WordPress (i.e. use the default permalink structure) and just add your subdirectory directives to the main .htaccess file ...
    Signature
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    {{ DiscussionBoard.errors[5478189].message }}

Trending Topics