2011-07-22 60 views
3

我想在Linux主機中使用.htaccess文件將鏈接重定向到另一個鏈接。你可以幫我嗎?如何在htaccess中創建永久鏈接

from: http://example.com/examp 
to: http://example.com/examp.php 

,另一個用於我的其他網站

from: http://example.com/examp 
to: http://example.com/user.php?u=examp 

回答

0

你會想看看的RewriteRules和知道/瞭解正則表達式。這將是這樣的:

 
    RewriteEngine on 
    RewriteRule ^(.*)\/examp$ /examp.php [R=301,L] 
    - and - 
    RewriteRule ^(.*)\/[a-zA-Z0-9\-\_\.]+$ /user.php?u=$1 [R=301,L] 

後者例如將採取什麼在中間的[],並將其放置在$ 1個變量

這裏是一個很好的鏈接,讓你開始: http://www.webweaver.nu/html-tips/web-redirection.shtml

4

您將需要mod_rewrite爲此啓用。開始將這些線條成的.htaccess:

RewriteEngine On 
RewriteBase/

TBH我不是100%肯定你是什麼意思完全相同的永久和你想如何重定向,所以我會爲每個2個變種URL:重寫(內部重定向)和重定向(301永久重定向)。

1. http://example.com/examp這將重寫(內部重定向)請求http://example.com/examp.php而URL將在瀏覽器保持不變:

RewriteRule ^examp$ examp.php [L] 

2.這將有一樣的正確重定向以上但與(301永久重定向)當URL將在瀏覽器改變:

RewriteRule ^examp$ http://example.com/examp.php [R=301,L] 

3. http://example.com/examp這將重寫(內部重定向)請求http://example.com/user.php?u=examp而URL將在瀏覽器保持不變:

RewriteRule ^examp$ user.php?u=examp [QSA,L] 

4.這將做同樣如上但適當的重定向(301永久重定向)時,URL將在瀏覽器中改變:

RewriteRule ^examp$ http://example.com/user.php?u=examp [QSA,R=301,L] 

有用的鏈接:http://httpd.apache.org/docs/current/rewrite/

相關問題