2013-10-08 88 views
0

我已經做了很多實驗。我已經嘗試使用.htaccess文件的每個可能的組合,但他們沒有爲我工作,所以我必須把這個查詢,我需要非常具體的解決方案。使用php代碼重寫URL

不使用CMS。該網站是一個使用php開發的電子商務網站。主機提供商是godaddy。

我的網站URL結構

  • 對於產品頁數= https://開頭WWW [點] sitename.com/product.php?product=productid
  • 對於類別頁面= https://開頭WWW [點] sitename.com/category.php?category=category-name
  • 對於SUBCAT頁數= https://開頭WWW [點] sitename.com/category.php?subcategory=sub-category-name

我要

  • 對於產品頁數= https://開頭WWW [點] sitename.com/product/productid/
  • 對於類別頁數= https://開頭WWW [點] sitename.com/category/category-name
  • 對於SUBCAT頁= https://開頭WWW [點] sitename.com/category/subcategory/sub-category-name

我怎樣才能做到這一點使用PHP代碼?

+0

你有沒有看在htaccess中使用mod_rewrite? http://forums.phpfreaks.com/topic/58436-neat-url/和http://www.sitepoint.com/guide-url-rewriting/ – ModulusJoe

+0

向我們展示您嘗試過並且無法使用的重寫代碼? – anubhava

+0

請嘗試此鏈接可能會有所幫助http://coding.smashingmagazine.com/2011/11/02/introduction-to-url-rewriting/ –

回答

0

也許這樣的事情

Options +FollowSymLinks 
RewriteEngine On 
RewriteBase/

Options -Indexes 

RewriteCond %{REQUEST_FILENAME} !-s [NC] 
RewriteCond %{REQUEST_FILENAME} !-d [NC] 

RewriteRule ^product/([0-9]+)$ product.php?product=$1 [L] 
RewriteRule ^category/([a-zA-Z0-9_]+)$ category.php?category=$1 [L] 
RewriteRule ^category/subcategory/([a-zA-Z0-9_]+)$ category.php?subcategory=$1 [L] 
+0

我試過這個。正如我所說沒有.htaccess代碼爲我工作。可能是該網站正在使用PHP代碼來重寫網址,因此我要求瞭解關於重寫網址的PHP代碼。 – anand