目標是在 HTTP_HOST 和 REQUEST_URI 之后創建一個“假”語言子目錄。
[Issue]
localhost/public_html causes 404, but localhost/public_html/index works.
當前代碼:
ErrorDocument 404 /public_html/404.php
ErrorDocument 500 /public_html/500.php
DirectoryIndex index.php
RewriteEngine On
RewriteRule ^$ /en/ [L,R=301]
# ASSIGN ENGLISH LANGUAGE PARAMETER IF NOT FOUND IN URL
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^(en|id|fr|ru|de|es|ro|tr|zh|ar)/ /en%{REQUEST_URI} [L,NC,R=302]
# ASSIGN LANGUAGE PARAMETER A VALUE IF FOUND IN URL
RewriteRule ^(en|id|fr|ru|de|es|ro|tr|zh|ar)/(.*) $2?language=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.] ?)/?$ $1.php [L,NC]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^.] ?)/?$ $1.html [L,NC]
檔案夾目錄:
xampp root folder
[
- public_html
]
website folder (public_html)
[
- .htaccess
- index.php
- contact.php
- style.css
- etc.php
]
更新:感謝anubhava,問題已成功解決!
uj5u.com熱心網友回復:
確保這 2 條規則是您最重要的規則:
ErrorDocument 404 /public_html/404.php
ErrorDocument 500 /public_html/500.php
DirectoryIndex index.php
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(index\.php)?$ /en/ [L,R=301]
# ASSIGN ENGLISH LANGUAGE PARAMETER IF NOT FOUND IN URL
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^(en|id|fr|ru|de|es|ro|tr|zh|ar)/ /en%{REQUEST_URI} [L,NC,R=302]
# ASSIGN LANGUAGE PARAMETER A VALUE IF FOUND IN URL
RewriteRule ^(en|id|fr|ru|de|es|ro|tr|zh|ar)/(.*) $2?language=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^.] ?)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^([^.] ?)/?$ $1.html [L]
確保在測驗此更改之前完全清除瀏覽快取。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/467180.html
標籤:.htaccess
