2014-02-28 127 views
0

我有以下的.htaccess代碼:htacces重寫URL不工作

Options +FollowSymlinks 
# Prevent Directoy listing 
Options -Indexes 
# Prevent Direct Access to files 
<FilesMatch "\.(tpl|ini|log)"> 
Order deny,allow 
Deny from all 
</FilesMatch> 

# SEO URL Settings 
RewriteEngine On 
RewriteRule ^products/(.*)/(.*)$ product_details.php?id=$1&name=$2 [L,QSA] 

我的網頁product_details.php是一個單獨的頁面中列出的產品的index.php通過像一個鏈接是指:

<a href="product_details.php?id=<?php echo $prod['product_id']; ?>&name=<?php echo friendlyURL($prod['name']); ?>" 

導致此: http://www.imprimanteetichete.ro/product_details.php?id=1&name=imprimanta-de-etichete-zebra-105sl-plus-203dpi

我已經與重寫規則不同的技術,嘗試了很多次,這是行不通的。我是.htaccess的新手,但它似乎是一個基本的東西。

我在做什麼錯?

+0

嘗試'^產品/([0-9] +)/(。 *)$'或'^ products /([0-9] +)/([a-zA-Z0-9 \ -_] +)$'這可能更安全 – Onimusha

+0

沒什麼不同,仍然顯示完整的url –

+0

Still顯示完整的網址?你想重寫URL還是重定向? – Onimusha

回答

0

試圖改變

RewriteEngine On 
RewriteBase/

RewriteBase http://example.com/ 
RewriteRule ^products/([0-9]+)/([a-zA-Z0-9\-_]+)$ product_details.php?id=$1&name=$2 [L,QSA] 
+2

RewriteBase /,沒有任何不同 'RewriteBase http://www.imprimanteetichete .ro /'給我一個內部服務器錯誤 –

0

你可以有以下規則:

RewriteEngine On 

RewriteCond %{THE_REQUEST} \s/+product_details\.php\?id=([^\s&]+)&name=([^\s&]+) [NC] 
RewriteRule^/products/%1/%2? [R=301,L,NE] 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^products/([^/]+)/([^/]+)/?$ /product_details.php?id=$1&name=$2 [L,QSA]