Nathan
Nathan

Reputation: 7855

How to use htaccess to rewrite a URL to remove a directory?

I have the following URL:

www.domain.com/test/blog/index.html

I'd like apache to always rewrite the url so that "test" will be removed, resulting in:

www.domain.com/blog/index.html

What's the best way to do this?

Upvotes: 1

Views: 1144

Answers (1)

xyz
xyz

Reputation: 396

This should do it nicely

Options +FollowSymLinks

RewriteEngine on
RewriteCond %{REQUEST_URI} !(.*)test
RewriteRule ^(.*)$ test/$1 [L]

This will remove the subdirectory from the url as you have specified; It would seem any other problems you are experiencing would be in respect to something else in the .htaccess file messing up the SymLinks.

I would suggest looking at the Apache error log to pin point exactly what the error is.

Hope this helps.

Upvotes: 2

Related Questions