[英]remove folder from url using .htaccess
我知道還有很多與此問題類似的問題,我嘗試了其中的一些問題,但是沒有運氣。
我有一個名為test.com的網站,我需要一個有人為test.com進行搜索以在test.com/home中顯示內容,而又不會在家中居住。
此刻我的htaccess文件如下所示:
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時,它顯示的是文件夾列表,而不是家庭內部的內容。
我究竟做錯了什么?
謝謝
您可以在根.htaccess中簡化規則。
RewriteEngine on
RewriteBase /
RewriteRule ^$ home/ [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!home/).+)$ home/$1 [L,NC]
在測試之前,請確保清除瀏覽器緩存。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.