.htaccess remove subdirectory name from all URLs

I was digging the net and haven’t found any proper solution for this issue. Basically, I want to remove subdirectory (subdirname) name from all URLs, e.g.:

http://test.com/subdirname/
http://test.com/subdirname/content/
http://test.com/subdirname/content/newpage

The website is based on WordPress and located in /subdirname. I’ve got two .htaccess files, one in root directory:

Read More
# Turn on URL rewriting
RewriteEngine On

# Installation directory
RewriteBase /

# Protect hidden files from being viewed
<Files .*>
    Order Deny,Allow
    Deny From All
</Files>

# Protect application and system files from being viewed
RewriteRule ^(?:application|modules|system)b.* index.php/$0 [L]

# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d

#RewriteCond %{REQUEST_URI} !^(/var|/static)
#RewriteCond %{REQUEST_URI} !^(/index.php|/var|/static)

# Rewrite all other URLs to index.php/URL
RewriteRule .* index.php/$0 [PT]

RewriteCond %{HTTP_HOST} ^(www.)?test.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !/subdirname/
RewriteRule ^(.*)$ /subdirname/$1 [L]

and second in /subdirname/ directory:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /subdirname/
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /subdirname/index.php [L]
</IfModule>
# END WordPress

If anyone has some tips how to solve it, please advice.

Related posts

Leave a Reply

1 comment