我有一个.htaccess规则,它获取url的第一个目录部分,并使用它从数据库中查找产品,如下所示。我使用以下规则,它工作得很好:
RewriteRule ^([-_a-z0-9]+)?$ /product.php?product_url=$1 [NC,L]
问题是,当我访问主页www.website.com/时,它试图查找空白产品。如果我想访问主页,我必须使用www.website.com/index.php。
我怎样才能保持上面的url结构,而把www.website.com/ show主页变成index.php呢?
发布于 2018-06-23 04:25:51
这应该跳过index.php
RewriteRule ^index\.php$ - [L]
RewriteRule ^([-_a-z0-9]+)?$ /product.php?product_url=$1 [NC,L]
发布于 2018-06-23 04:38:44
主要问题是您的正则表达式也匹配空字符串。
您应该改用此规则:
RewriteRule ^([-_a-z0-9]+)/?$ product.php?product_url=$1 [NC,L,QSA]
此正则表达式使请求URI中的尾部斜杠可选,但不匹配空字符串(登录页面)
此外,请考虑使用以下两个条件跳过此次重写的所有文件和目录:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([-_a-z0-9]+)/?$ product.php?product_url=$1 [NC,L,QSA]
发布于 2018-06-23 04:32:06
你可以尝试这样做:同时检查并修改我曾经问过的这个问题,看看你是否可以调整它,Perform If statements for a specific file name in .htaccess
RewriteRule ^index\.php$ - [L] //This would make it skip index.php and look at product.php
RewriteRule ^([-_a-z0-9]+)?$ /product.php?product_url=$1 [NC,L]
https://stackoverflow.com/questions/50995075
复制相似问题