remove folder from url using .htaccess

喜欢而已 提交于 2019-12-25 14:06:32

问题


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:


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.



来源:https://stackoverflow.com/questions/32661405/remove-folder-from-url-using-htaccess

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!