2014-03-26 51 views
0

我試圖將www.example.org.uk重定向到example.org.uk/subdirectory,然後隱藏該子目錄 - 因此它只在地址欄上顯示www.example.org.uk。如何將根文件夾重定向到子目錄並在GoDaddy上使用.Htaccess隱藏它?

這是我用的是原來的代碼(從https://my.bluehost.com/cgi/help/347):

# BlueHost.com 
# .htaccess main domain to subdirectory redirect 
# Do not change this line. 
RewriteEngine on 
# Change example.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www.)?example.org.uk$ 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/subdirectory/ 
# 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 ^(.*)$ /subdirectory/$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.)?example.org.uk$ 
RewriteRule ^(/)?$ subdirectory/index.php [L] 

的問題是,沒有這個代碼的工作。

搜索#1和使用意見後 - 這是當前的代碼:

Options +FollowSymLinks -Multiviews 

<IfModule mod_rewrite.c> 

# BlueHost.com 
# .htaccess main domain to subdirectory redirect 
# Do not change this line. 
RewriteEngine on 
# Change example.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www.)?grampianyoga.org.uk$ 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/gya2/ 
# 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 ^(.*)$ /gya2/$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.)?grampianyoga.org.uk$ 
RewriteRule ^(/)?$ gya2/index.php [L]</IfModule> 

不幸的是顯示一個內部錯誤,這是什麼錯誤文件指出:[Wed Mar 26 14:22:35 2014] [9566783] [core:alert] [client 97.74.104.6:60525] /var/chroot/home/content/83/9566783/html/.htaccess: RewriteRule: bad flag delimiters

我使用GoDaddy的,我相信他們有自己的設置。有沒有人有什麼建議?嘗試支持,顯然他們 無法幫助腳本。

+0

嘗試在感興趣的目錄上方的父目錄中的'.htaccess'中添加以下內容:'RedirectMatch ^/foo/$/foo/bar /'或'RedirectMatch ^/foo/$/bar/baz /' 。另請參閱[如何讓apache2重定向到子目錄](http://serverfault.com/q/9992/145545)。 – jww

回答

1

我想線

RewriteCond %{REQUEST_URI} !^/subdirectory/ 

更改爲

RewriteCond %{REQUEST_URI} !^/subdirectory/? 

,使得拖尾/是可選。該代碼,與-f-d檢查,不會,如果你碰巧給現有的文件或目錄被觸發。假設沒有,

RewriteRule ^(.*)$ /subdirectory/$1 

應該靜靜發送旅客子目錄(現有URI之前插入 /子目錄)。

我不知道爲什麼最後兩行在那裏。如果您關閉尾部/需求(如上所述),它們可能已經處理完畢。嘗試對它們進行評論(使用#)。

如果還是不行,有可能是一些與GoDaddy的設置不同。你應該討論你想用技術支持來做什麼。

更新:你最新的.htaccess的修改版本

Options +FollowSymLinks -Multiviews 

<IfModule mod_rewrite.c> 

# BlueHost.com 
# .htaccess main domain to subdirectory redirect 
# Do not change this line. 
RewriteEngine on 
# Change example.com to be your main domain. 
RewriteCond %{HTTP_HOST} ^(www\.)?grampianyoga\.org\.uk$ 
# Change 'subdirectory' to be the directory you will use for your main domain. 
RewriteCond %{REQUEST_URI} !^/gya2 
RewriteRule ^(.*)$ /gya2/$1 [L] 

</IfModule> 

RewriteCond %{HTTP_HOST} ^(www\.)?grampianyoga\.org\.uk$行可能是不必要的(但是無害的),除非你有停放的域名,子站點,附加域等

+0

仍然不能正常工作,這是我在錯誤日誌中收到的內容:[Wed Mar 26 14:22:35 2014] [9566783] [core:alert] [client 97.74.104.6:60525]/var/chroot/home/content /83/9566783/html/.htaccess:重寫規則:壞標誌分隔符你有任何其他建議嗎? –

+0

壞旗分隔符?你的.htaccess現在是什麼樣的(請把它添加到你的第一篇文章的底部)。我從來沒有在.htaccess中看到過這個消息。 –

+0

好的,修改了原來的帖子。希望這可以幫助。 –

相關問題