2017-02-21 88 views
1

我有一個託管平臺http://example.com的託管域http://example2.com.htaccess主域到子文件夾,但/子文件夾仍然可到達

問題是,如果我去http://example2.com/example2/fr,我沒有被重定向到http://example2.com/fr,我嘗試瞭解決方案,但仍然保持重定向循環。

在的public_html文件夾中,有一個子文件夾/例題與文件http://example2.com

> public_html 
    - .htaccess 
    - index.php 
    > assets 
    > css 
    > js 
    > example2 
    - .htaccess 
    - index.html 
    > fr 
     - index.html 
    > en 
     - index.html 

現在,在文件夾中的public_html,在我的.htaccess文件我的重定向規則是:

<IfModule mod_rewrite.c> 
    RewriteEngine on 

    # Redirect the example2 to the subfolder /example2 
    RewriteCond %{HTTP_HOST} ^(www\.)?example2\.com$ [NC] 
    RewriteRule !^example2/ /example2%{REQUEST_URI} [L,NC] 
</IfModule> 

在/ example2文件夾中,我的htaccess文件如下重定向:

<IfModule mod_rewrite.c> 
    RewriteEngine On 
    RewriteCond %{HTTP_HOST} !^www\. 
    RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

    RewriteRule ^index\.html$/[R=301,L] 
    RewriteRule ^(.*)/index\.html$ /$1 [R=301,L] 

    #RewriteRule ^(.*)$ /$1 [R=301,L] 
</IfModule> 
+0

如果刪除/subfolder/.htaccess,會發生什麼情況? – starkeen

回答

1

您的/example2/.htaccess應該是這樣的:

RewriteEngine On 

RewriteCond %{HTTP_HOST} !^www\. 
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] 

RewriteRule ^index\.html$/[R=301,NC,L] 

RewriteRule ^(.*)/index\.html$ /$1 [R=301,NC,L] 

# remove /example2/ from URLs 
RewriteCond %{THE_REQUEST} \s/+example2(/\S*)\s [NC] 
RewriteRule^%1? [R=301,L,NE] 
+1

非常感謝。奇蹟般有效 :) – ReBa

相關問題