我很難理解htaccess重寫/重定向是如何工作的。我已經有超過20篇關於它的文章,但我沒有理解如何正確編寫規則的邏輯和語法。在子文件夾下如何用htaccess重寫或重定向子目錄?
我目前沒有與的public_html文件夾 我們有我們的主網站的子文件夾/站點下的服務器,這是一個WordPress站點 我們還有其他的網站(也是WordPress站點),我們使用電子學習/培訓
我需要讓自己的網站(domain.com),同時具有domain.com/learning指向的public_html /培訓
我試圖understad htaccess的查詢如何爲指向/的public_html /網站工作如RewriteCond或RewriteRule
這裏是我當前的代碼:
# Use PHP5.4 Single php.ini as default
AddHandler application/x-httpd-php54s .php
# File modified on Sun Mar 30 01:22:23 2014 by server
# For security reasons, mod_php is not used on this server. Use a php.ini file for php directives
# php_value max_execution_time 90
# BlueHost.com
# .htaccess main domain to subdirectory redirect
# Do not change this line.
# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch
RewriteEngine on
#RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
# Change 'subdirectory' to be the directory you will use for your main domain.
#RewriteCond %{REQUEST_URI} !^/site/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'subdirectory' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /site/$1
# Change example.com to be your main domain again.
# Change 'subdirectory' to be the directory you will use for your main domain
# followed by/then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ site_en/index.html [L]
# .htaccess main domain to subdirectory redirect
# Do not change this line.
RewriteEngine on
# Change domain.com to be your main domain.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
# Change 'site to be the directory you will use for your main domain.
RewriteCond %{REQUEST_URI} !^/learning/
# Don't change the following two lines.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Change 'site' to be the directory you will use for your main domain.
RewriteRule ^(.*)$ /learning/$1
# Change domain.com to be your main domain again.
# Change 'site' to be the directory you will use for your main domain
# followed by/then the main file for your site, index.php, index.html, etc.
RewriteCond %{HTTP_HOST} ^(www.)?domain.com$
RewriteRule ^(/)?$ learning/index.html [L]
我說得有點快。我們的學習網站使用htpasswd進行保護。將這兩個代碼放在一起,使得主站點不能在沒有輸入密碼的情況下訪問。 – chris
@chris,你爲什麼收回答案驗證隊友? –
,因爲它不起作用。我用當前的htaccess發佈了最初的主題。 – chris