我正在為 .htaccess 檔案而苦苦掙扎。我已將 wordpress 安裝在子目錄“wordpress”中。在根檔案夾中,如果 htaccess 包含以下內容:
Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule !^wordpress/ /wordpress%{REQUEST_URI} [L,R=301]
</IfModule>
重定向有效,但如何隱藏子檔案夾“wordpress”?
提前 THX
編輯:現在嘗試了以下內容,但仍然無法正常作業:
根 htaccess:
Order Allow,Deny
Allow from all
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
</IfModule>
WordPress htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteBase /wordpress/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wordpress/index.php [L]
</IfModule>
EDIT2:我的整個根 htaccess 現在看起來像這樣:
Allow from all
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
如果我輸入www.example.com,我將被重定向到 example/wordpress/home、example/wordpress/contact 等等...
我想隱藏 wordpress 目錄,例如 example/home、example/contact 等
uj5u.com熱心網友回復:
重定向有效,但如何隱藏子檔案夾“wordpress”?
你不應該“重定向”。您應該在內部重寫請求。洗掉R標志。
例如:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule !^wordpress/ wordpress%{REQUEST_URI} [L]
替代字串上的斜杠前綴也不是必需的。
這假設您在子目錄中有標準的 WP.htaccess檔案。/wordpress
更新:還要確認您已從/wordpressWordPress 常規設定中的“網站地址”和“網站地址”中洗掉了子目錄。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/430509.html
