.htaccess – Add subdirectories to all directories… here is a solution to the problem.
.htaccess – Add subdirectories to all directories
With .htaccess I’m trying to add a directory to all URLs, but there doesn’t seem to be any luck. I could do this for each directory, but wondered if there was an easier way to fix this.
I need all my URLs, for example:
www.example.com/abc
www.example.com/def
www.example.com/ghi
Append the directory ‘test’ to make the URL look like this:
www.example.com/test/abc
www.example.com/test/def
www.example.com/test/ghi
Try PHP, but that seems a bit silly, so .htaccess seems like the best option.
Solution
With mod_rewrite, you can try adding it to your .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /test/$1 [L]
If you do need a redirect (rather than a “behind-the-scenes” rewrite), change [L] to [
R,L].