2013-12-17 32 views
1

我試圖弄清楚歐TA重寫規則直接某些URL對特定的PHP文件:mod_rewrite的:重寫規則重定向某些URL對特定PHP文件

該文件是watch.php

的URL都喜歡這http://mysite/watch/193916/1/watch-skysports.html

我想重定向這個

http://mysite/watch.php?file=watch/193916/1/watch-skysports.html 

我在htaccess文件試試

Options FollowSymLinks 
<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteRule watch/(*)/(*)/(*).html match.php?file=$1 [L] 
</IfModule> 

但它不工作 注意:mod_rewrite的啓用

回答

0

您沒有正確的正則表達式。 *不是通配符,而是表示一定數量的字符。試試這個:

Options FollowSymLinks 
<IfModule mod_rewrite.c> 
RewriteEngine on 
RewriteRule ^(watch/[0-9]+/[0-9]+/.*\.html)$ /match.php?file=$1 [L] 
</IfModule> 
+0

謝謝你的好幫手只要它有效。 – user3080937

+0

我有問題,因爲我所有的CSS,JS,圖像鏈接是相對的,當我在頁面http://mysite/watch/193916/1/watch-skysports.html相關鏈接將是'手錶/ 193916/1 /'如何解決這個問題,而不必編輯絕對URL的所有鏈接 – user3080937

+0

@ user3080937嘗試將其添加到頁面頭部:'' –