htaccess重写网址无法正常工作

时间:2014-02-28 11:10:32

标签: php .htaccess

我有以下.htaccess代码:

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

我在Rewrite规则上尝试了多次不同的技术,它只是不起作用。我是.htaccess的新手,但这似乎是一件基本的事情。

我做错了什么?

2 个答案:

答案 0 :(得分: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]

答案 1 :(得分: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]