remove folder from url using .htaccess

2019-09-09 09:43发布

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

1条回答
Rolldiameter
2楼-- · 2019-09-09 10:18

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.

查看更多
登录 后发表回答