WiththeWind
WiththeWind

Reputation: 153

Replacing directory in url htaccess

I have some htaccess rules in place to try and create a setup similar to a vhost. My website is on shared hosting so I cannot control the vhosts so I am wanting to mimic it via htaccess rules, but I am having a tough time figuring out how to remove one of the directories from the url.

RewriteCond %{HTTP_HOST} ^test2.mydom.com$ [NC]
RewriteCond %{REQUEST_URI} !(.*)test2
RewriteRule ^((?!test2/).*)$ /test2/$1 [L,NC]

Currently these are the rules I have set in place and it is able to redirect to the correct folder and it removes the test2 directory as I want but it's making it so none of the css loads.

This is another set of rules I have for another site and it works and the css can load perfectly but it keeps the test in the url

 RewriteCond %{HTTP_HOST} ^test.mydom.com$ [NC]
 RewriteCond %{REQUEST_URI} !^/test/
 RewriteRule ^(.*)$ /test/$1 [L,R]

Upvotes: 1

Views: 37

Answers (1)

WiththeWind
WiththeWind

Reputation: 153

I was able to get this to work by simply removing the slash in the rewrite rule. Changed to it to:

RewriteRule ^((?!test2).*)$ /test2/$1 [L,NC]

Upvotes: 1

Related Questions