使用的.htaccess从URL中删除文件夹 [英] remove folder from url using .htaccess
问题描述
我知道有很多其他的问题,与此类似,我想followinf其中一些的,但没有运气。
I know there are plenty of other questions similar to this one, i tried followinf some of those, but with no luck.
我有一个网站叫test.com,我需要,当有人seraches为test.com展现在test.com/home的内容,而不在uerl有回家。
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.
目前我的htaccess文件看起来是这样的:
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$
但是当我键入test.com它显示一个文件夹列表,里面没有回家的内容。
but when i type test.com it shows a list of folders, not the content inside home.
我究竟做错了什么?
感谢
推荐答案
您可以简化你的规则,这根的.htaccess
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.
这篇关于使用的.htaccess从URL中删除文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!