1
我試圖從URL中隱藏一個子目錄.htaccess。我有一個PHP腳本,每當客戶進入網站時執行。它是根目錄Apache目錄中的index.php
。該腳本確定要在網站中使用的語言並重定向到目標目錄。英語是我的默認語言,所以我需要「en」目錄隱藏在URL中,同時將根目錄中的所有URL請求重定向到「en」文件夾,以便它們不會生成404 HTTP錯誤。我部分地與以下行來實現這一點:.htaccess總是隱藏URL中的某個子目錄
#Remove en/ directory from URL
RewriteRule ^$ en/
#Forward all the requests to en/ directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ en/$1
當請求轉發到「EN」目錄,這是在URL中再次顯示。這將是流動:
- 用戶類型:http://domain.com
- index.php文件重定向到http://domain.com/en,因爲這是檢測到的語言
- 的.htaccess規則隱藏/ EN目錄中,同時將網址http://domain.com
- 客戶端類型http://domain.com/panel來訪問他們的用戶面板
- htaccess的重定向到http://domain.com/en/panel
如何刪除「en」目錄在列表中的最後一個操作之後離開URL http://domain.com/panel?有沒有更好的方法來管理這種行爲?
目前的規定:
Options -Indexes +FollowSymlinks -MultiViews
ErrorDocument 404 /404.php
RewriteEngine On
RewriteRule ^/?$ en/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^((?!en/).*)$ en/$1 [L,NC]
#Prevent direct access to PHP Scripts
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule \.php$ - [R=404,L]
#Remove WWW
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
我得到了和以前一樣的行爲。注意:.htaccess文件位於根目錄中。 – ProtectedVoid
剛剛添加完整的.htaccess – ProtectedVoid
我收到了同樣的結果。我確定我清除了緩存。額外的說明:當試圖訪問不是「en」的其他目錄時,我得到404錯誤。例如:http://domain.com/es給出404錯誤(「es」目錄與「en」存在相同) – ProtectedVoid