2016-07-26 189 views
0

我有一個基於php的動態網站。 所以,我只是想知道我怎麼能自動重定向這個網址動態網址到靜態url重寫和重定向

/convert.php?id=any-id&v=any-string [L] 

/tutorial/any-string/any-id.html 

我已經創建了下面的htaccess代碼

Options +FollowSymlinks 
RewriteEngine on 
RewriteOptions inherit 
RewriteRule ^videos/([^/]*)\.html$ /search.php?s=$1 [L] 
RewriteRule ^tutorial/([^/]*)/([^/]*)\.html$ /convert.php?id=$1&v=$2 [L] 

我能得到靜態但我想要的是,如果有人在瀏覽器中輸入動態url,他/她應該自動重定向到新的靜態url。

有什麼建議嗎?

回答

0

更改您的.htaccess文件以反映以下規則,它將按照您的要求工作。

Options +FollowSymlinks 
RewriteEngine on 
RewriteOptions inherit 
RewriteRule ^videos/([^/]*)\.html$ /search.php?s=$1 [L] 
RewriteRule ^tutorial/([^/]*)/([^/]*)\.html$ /convert.php?id=$1&v=$2 [L] 
RewriteCond %{QUERY_STRING} (^|&)id=any-id($|&) 
RewriteCond %{QUERY_STRING} (^|&)v=any-string($|&) 
RewriteRule ^convert\.php$ /tutorial/any-string/any-id.html? [L,R=301] 
+0

在此URL,任何字符串與任何-ID將是這將得到自動改變的動態值,你認爲這是寫在正確的方式? @ error2007s – Kapil

+0

上面是正確的。 – error2007s

0

添加其他重寫規則來處理動態URL中底:

Options +FollowSymlinks 
RewriteEngine on 
RewriteOptions inherit 

RewriteRule ^videos/([\w-]+)\.html$ search.php?s=$1 [L,QSA,NC] 

RewriteRule ^tutorial/([^/]+)/([\w-]+)\.html$ convert.php?id=$1&v=$2 [L,QSA,NC] 

RewriteRule ^([\w-]+)/([\w-]+)\.html$ convert.php?id=$1&v=$2 [L,QSA,NC]