2013-02-16 107 views
1

我困在這個.htaccess問題中,無法獲得解決方案。試過一切,但因爲我是新的htaccess可能是代碼只是不匹配,它給了我一個錯誤。.htaccess重定向問題

有一個PHP文件,我的工作..

這是結果,我現在得到

http://website.com/page.php?url=diploma-in-film-acting

現在,我想這是這樣

http://website.com/diploma-in-film-acting

工作

或可能是這個

http://website.com/diploma-in-film-acting.html

我該如何解決這個問題?

我已經使用這個代碼

我已經這樣做,但我得到一個404錯誤,當我加入這個到URL http://website.com/diploma-in-film-acting.html

RewriteEngine On 

RewriteRule ^([a-zA-Z0-9-/]+).html$ page.php?url=$1 
RewriteRule ^([a-zA-Z0-9-/]+).html/$ page.php?url=$1 

感謝

+0

使用Apache'mod_rewrite' – mithunsatheesh 2013-02-16 07:14:28

+0

感謝@mithunsatheesh ......我,我需要用這個mod_rewrite的,但我該怎麼添加到htaccess的使它看起來像? – user1689231 2013-02-16 07:16:17

+0

如果你在本地主機上測試了這個,你需要使用rewritebase進行正確的重定向。 – Dev 2013-02-16 07:32:29

回答

0

它現在: -

RewriteEngine On 

RewriteRule ^([a-zA-Z0-9-/]+).html$ page.php?url=$1 
RewriteRule ^([a-zA-Z0-9-/]+).html/$ page.php?url=$1 
2
RewriteEngine On 
RewriteRule ^([^/]*)\.html$ /page.php?url=$1 [L] 
+0

我已經做到了這一點,但我得到了一個404錯誤,當我將它添加到URL http://website.com/diploma-in-film-acting.html RewriteEngine在 RewriteRule ^([a-zA-Z0 9)//+)。html $ page.php?url = $ 1 RewriteRule ^([a-zA-Z0-9 - /] +)。html/$ page.php?url = $ 1 – user1689231 2013-02-16 07:22:32

+0

您必須添加規則在.htaccess文件,然後打開這個網址: - website.com/diploma-in-film-acting.html – 2013-02-16 07:25:51

+0

添加...選項+ FollowSymLinks ..在開始 – 2013-02-16 07:30:16

1

使用mod_rewrite Apache的!而在你.htaccess,給這個:

RewriteEngine On 
RewriteRule ^([^/]*)\.html$ /page.php?url=$1&%{QUERY_STRING} [L] 

對於基於目錄的重寫,使用此:

RewriteEngine On 
RewriteRule ^([^/]*)\.html$ /page.php?url=$1&%{QUERY_STRING} [L] 
RewriteCond %{SCRIPT_FILENAME} !-f 
RewriteCond %{SCRIPT_FILENAME} !-d 
RewriteRule ^(.*)$ /page.phpurl$1&%{QUERY_STRING} 

或者,如果您有任何查詢字符串,將要通過&%{QUERY_STRING}通過。

+0

我已經這樣做,但我得到一個404錯誤,當我此添加到URL http://website.com/diploma-in-film-acting.html '代碼' RewriteEngine敘述在 重寫規則^([A-ZA-Z0-9 - /] +)。HTML $ page.php ?url = $ 1 RewriteRule ^([a-zA-Z0-9 - /] +)。html/$ page.php?url = $ 1 – user1689231 2013-02-16 07:23:44

+0

沒有,請嘗試從這裏開始說。 :)複製完整的一個,並嘗試這兩個網址。 – 2013-02-16 07:24:16