2014-04-20 32 views
1

//對不起,對於語法錯誤和其他任何錯誤的事情,英語不是我的母語(不知道我是否拼寫得好)。htaccess獲取seo url的參數

我使用htaccess製作了SEO友好的網址。唯一的問題是,我總是會從url中獲取信息(使用GET),而現在則使用SEO友好的URL,我無法做到這一點。

我以前的網址是這樣的:

http://rasolutions.eu/blogitem?id=2 

所以在PHP這將是$ _GET [「身份證」],這將是2。但現在,我已經有了SEO友好的URL是這樣的:

http://rasolutions.eu/blogitem/2/ 

現在我的PHP腳本無法看到他會從哪裏得到ID,所以它會將我返回到主頁。

我已經谷歌搜索,你需要使用(。*)在htaccess中,但我不知道在哪裏或如何。 我htaccess的代碼是這樣ATM:

Options +MultiViews 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

# WWW to not WWW. 
RewriteCond %{HTTP_HOST} ^www\.rasolutions\.eu$ 
RewriteRule ^/?$ "http\:\/\/rasolutions\.eu\/" [R=301,L] 
    RewriteRule ^blog/(.*)([0-9]+)/$ blog.php?page=$1 [NC,L] 
    RewriteRule ^blogitem/(.*)([0-9]+)/$ blogitem.php?id=$1 [NC,L] 

回答

1

最後兩個規則應該是正確的沒有(.*)根據示例語法您發佈。和你在一個靈活的方式來照顧尾部斜槓(/)的:

Options +MultiViews 
RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^([^\.]+)$ $1.php [NC,L] 

# WWW to not WWW. 
RewriteCond %{HTTP_HOST} ^www\.rasolutions\.eu$ 
RewriteRule ^(.*)$ http://rasolutions.eu$1 [R=301,L] 

RewriteRule ^blog/([0-9]*)/?$  blog.php?page=$1 [NC,L] 
RewriteRule ^blogitem/([0-9]*)/?$ blogitem.php?id=$1 [NC,L] 

一般是用RewriteLogging如果你有機會到它非常好主意。它可以幫助您在每個單獨的子步驟中準確瞭解重寫引擎內部發生了什麼,而不必猜測會發生什麼情況。

+0

對不起,但這仍然不能解決問題。 PHP腳本仍然不知道從哪裏獲取ID,我怎麼能在htaccess中指定在博客/頁面出現之後。 – RezaM

+0

當然會的。 ''_GET ['id']'('$ _GET ['page']')將保存'http:// rasolutions.eu/blogitem/2'中最後一個斜槓('/')後指定的內容。這就是這種重寫的重點!你只需要確保這兩條線確實符合要求,所以實際上是適用的! – arkascha

+0

這就是說:你是否真的確信這些例子是你給了_really_結尾的斜槓?爲什麼? – arkascha