2013-03-06 106 views
0

我爲我的組織設置了URL縮短服務。我想重寫短網址到我的index.php文件,但重定向請求根到我的主網站,即:mod_rewrite重定向根目錄,重寫子目錄

請求:short.domain.tld/ABC
用戶認爲:短。使用domain.tld/ABC
網頁中投放了起來:short.domain.tld/index.php的代碼= ABC

請求:short.domain.tld/
用戶看到:website.domain.tld
網頁中投放up:website.domain.tld(在我的網站服務器上)

我的.htaccess文件是目前:

Options +FollowSymLinks 
RewriteEngine on 

RewriteCond %{REQUEST_FILENAME} !-s 
RewriteRule ^/(.*)$ index.php?code=$1 [L] 
RewriteRule ^.*$ http://website.domain.tld/ 

我不確定如何爲域的根子目錄請求,並請求進行區分。

回答

1

您可以在根目錄下的.htaccess文件試試這個:

Options +FollowSymlinks -MultiViews 
RewriteEngine On 
RewriteBase/

RewriteCond %{HTTP_HOST} short\.domain\.tld [NC] 
RewriteCond %{REQUEST_URI} !index\.php  [NC] 
RewriteRule ^([^/]+)/? /index.php?code=$1 [NC,L] 

RewriteCond %{HTTP_HOST} short\.domain\.tld [NC] 
RewriteCond %{REQUEST_URI} ^/$  
RewriteRule .* http://website.domain.tld [R=301,L] 

地圖內部

http://short.domain.tld/abc帶或不帶斜線(在地址欄中顯示)

http://short.domain.tld/index.php?code=abc

假設字符串abc是動態的。


或永久

http://short.domain.tld/重定向不段軌跡

要:

http://website.domain.tld/(顯示在地址欄)

+0

謝謝!我相信我的短語錯誤是正確的。我修改了一下規則 - 刪除了RewriteBase指令並刪除了%{HTTP_HOST}指令 - 一切仍然有效。再次感謝。 – Pickle 2013-03-07 16:17:18