2015-12-07 49 views
2

我想重寫一個我的urls到漂亮的urls,但我似乎無法弄清楚。這是我嘗試過的。.htaccess漂亮的URL重寫像文件夾

我的文件夾佈局

-index.php 
-.htaccess 
-/product 
    -category.php 
    -index.php 
    -product.php 

我htaccess文件

<IfModule mod_rewrite.c> 
RewriteEngine On 
RewriteRule ^([^/]+)/?$ category.php?category_id=$1 [L,QSA] 
</IfModule> 

即時特林打開這個網址

http://example.com/product/category.php?category_id=1&category=car-and-buses 

到這個網址

http://example.com/product/1/car-and-buses 

一切是我的嘗試至今讓我懷念的配置錯誤或401 ..我的瀏覽器

+0

你的.htaccess在產品'目錄裏面的任何機會? – anubhava

回答

1

我猜你嘗試打開

http://example.com/product/1/car-and-buses 

這個,所以你可以獲取您的類別中的參數。與$ _GET [ 'CATEGORY_ID'] PHP的

http://example.com/product/category.php?category_id=1&category=car-and-buses 

試試這個,放置.htaccess文件在你的根

<IfModule mod_rewrite.c> 
    RewriteEngine On  
    RewriteRule ^product/(.*)/(.*) /product/category.php?category_id=$1&category=$2 [QSA,L] 
</IfModule> 

編輯!

試試這個,因爲上面的解決方案不適合你。這應該重寫所有的請求到你的index.php。這不是你的問題的解決方案,但嘗試這一點,以確保沒有任何其他問題你的.htaccess文件

RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^([^?]*)$ /index.php?page=$1 [NC,L,QSA] 
+0

獲取「未找到」錯誤 – Divakarcool

+0

您可以直接訪問頁面嗎? http://example.com/product/category.php?category_id=1&category=car-and-buses – Andy

+0

是的,是不是有問題? – Divakarcool