【发布时间】:2012-02-16 13:40:38
【问题描述】:
我已经编写了 .htaccess 文件如下:
Options +FollowSymLinks
RewriteEngine On
#open the product details page with the Product Number with PN prefix
RewriteRule ^((products/|product/|)PN[0-9-]+)/?$ product.php?pno=$1
#open the product search page for a particular category
RewriteRule ^((bat|ref|acc)[A-Za-z0-9-]+)/?$ search.php?cat=$1 [NC]
#open the product search page for a particular category
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([A-Za-z0-9-_.,]+)/?$ search.php?search =$1 [NC]
RewriteRule !\.(html|php)$ - [S=4]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4-$5 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_([^_]*)_(.*)$ $1-$2-$3-$4 [E=uscor:Yes]
RewriteRule ^([^_]*)_([^_]*)_(.*)$ $1-$2-$3 [E=uscor:Yes]
RewriteRule ^([^_]*)_(.*)$ $1-$2 [E=uscor:Yes]
RewriteCond %{ENV:uscor} ^Yes$
如果查询字符串值中有点(.),则无法接受。现在,它解决了,但不能接受它以前的规则。
此外,如果给出 URL“URL/products/PN123”或“URL/product/PN123”,我希望它正确重写“URL/product.php?pno=PN123”。请注意,如果使用正确的 CSS 正确给出“URL/PN123”,它可以正确重定向。 AND "URL/product/PN123" 也可以检索数据,但不能正确显示 CSS。
【问题讨论】:
-
什么发送
Object not found?search.php 查询? -
你能不能只在字符类中添加一个点?
^([A-Za-z0-9-_.]+)/?$ -
@Michael,我添加了一个点,但它不起作用。在这种情况下,它将进入空白页面而不是错误消息。
-
如果您有空白页,请在 PHP 中打开
display_errors。ini_set('display_errors', 1);你可能有语法错误或未过滤的 SQL 查询什么的...... -
是的,display_errors 已开启。在这种情况下,它不会产生 PHP 错误。它只是挂在空白页上。
标签: regex apache .htaccess mod-rewrite