[英]Redirect and remove folder in url .htaccess
我試圖從http://example.org/family/重定向到http://example.org/family/public,而不在url中顯示文件夾public,所以我想在重定向后保持url不變。
我一直在閱讀許多不同的解決方案,但沒有得到想要的結果。 目前,我在“家庭”文件夾中有一個.htaccess,但它重定向到公用文件夾並顯示404錯誤:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /family
RewriteCond %{REQUEST_URI} !^/public
RewriteRule (.*) public/$1 [L]
</IfModule>
它應該在index.php中顯示內容,但不顯示。 公用文件夾中的.htaccess是:
<IfModule mod_rewrite.c>
RewriteEngine On
# Handle Authorization Header
RewriteCond %{HTTP:Authorization} .
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect Trailing Slashes If Not A Folder...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
RewriteRule ^/public/(.*) /$1 [QSA]
</IfModule>
這將是您的解決方案,它將所有請求重定向到子文件夾public
RewriteEngine On
RewriteBase /family
RewriteCond %{REQUEST_URI} !^/family/public
RewriteRule (.*) family/$1 [L]
不知道這是否是最好的解決方案,但是您可以嘗試ProxyPass:
如果您使用的是Apache,請編輯httpd.conf
添加此行
ProxyPass /family http://example.org/family2/public
另外,請確保未注釋以下行,以便您獲得正確的代理和子模塊來重新路由http請求:
LoadModule proxy_http_module modules/mod_proxy_http.so LoadModule proxy_module modules/mod_proxy.so
然后重新啟動服務器,dir family2/public
中必須顯示給family
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.