Nick
Nick

Reputation: 14283

remove folder from url using .htaccess

I know there are plenty of other questions similar to this one, i tried followinf some of those, but with no luck.

I have a website called test.com and i need, when someone seraches for test.com to show the content in test.com/home, without having home in the uerl.

My htaccess file at the moment looks like this:

RewriteEngine on
RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule    /(.*) home/$1    [L]
    RewriteRule    /home/(.*) /$1    [L,R=302]

RewriteOptions inherit

RewriteCond %{HTTP_HOST} ^test\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.test\.com$

but when i type test.com it shows a list of folders, not the content inside home.

What am i doing wrong?

thanks

Upvotes: 0

Views: 1540

Answers (1)

anubhava
anubhava

Reputation: 786136

You can simplify your rules to this in root .htaccess

RewriteEngine on
RewriteBase /

RewriteRule ^$ home/ [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!home/).+)$ home/$1 [L,NC]

Make sure to clear your browser cache before testing this.

Upvotes: 1

Related Questions