目前,我有一个系统可以通过htaccess工作,就像每次将新产品添加到系统时需要硬核URL一样,如下所示
RewriteRule ^18th-and-19th-century$ sub_category.php?id=18th-and-19th-century
RewriteRule ^20th-century-furniture$ product.php?id=20th-century-furniture
RewriteRule ^pair-lacquer-cabints$ product_info.php?id=pair-lacquer-cabints
并且静态页面也很少,
RewriteRule aboutus aboutus.php?
RewriteRule contactus contactus.php?
这里的想法,我想要的是将产品信息,类别信息重定向到一些index.php并按原样访问静态页面,
RewriteRule aboutus$ aboutus.php?
RewriteRule contactus contactus.php?
RewriteRule ^ index.php?
我尝试了这个但是每次它都需要我index.php页面,我认为这里需要一些条件但不能理解如何前进
先谢谢
答案 0 :(得分:0)
尝试
RewriteEngine On
RewriteRule ^sub_category/([^/]*)$ /sub_category.php?id=$1 [L]
RewriteRule ^product/([^/]*)$ /product.php?id=$1 [L]
RewriteRule ^product_info/([^/]*)$ /product_info.php?id=$1 [L]
输出网址
http://example.com/sub_category/18th-and-19th-century
http://example.com/product/20th-century-furniture
http://example.com/product_info/pair-lacquer-cabints
答案 1 :(得分:0)
您已在同一目录级别编写了所有网址,因此您无法编写动态.htaccess规则。您需要在所有不同类型的URL中添加一些标识符或某些模式,这些URL将访问不同的php页面。
RewriteRule ^18th-and-19th-century$ sub_category.php?id=18th-and-19th-century
RewriteRule ^20th-century-furniture$ product.php?id=20th-century-furniture
RewriteRule ^pair-lacquer-cabints$ product_info.php?id=pair-lacquer-cabints
RewriteRule aboutus aboutus.php
与上述页面一样,您可以使用以下格式的网址
Subcategory URL: www.domain.com/18th-and-19th-century
Product URL: www.domain.com/18th-and-19th-century/list or www.domain.com/18th-and-19th-century/20th-century-furniture
Product info: www.domain.com/18th-and-19th-century/20th-century-furniture/pair-lacquer-cabints
OR
Subcategory URL: www.domain.com/category/18th-and-19th-century
Product URL: www.domain.com/product/20th-century-furniture
Product info: www.domain.com/product_info/pair-lacquer-cabints
因此,您可以定义级别并编写重写规则。
同样,您可以为静态页面编写URL
www.domain.com/content/aboutus
www.domain.com/content/contactus
或
www.domain.com/aboutus
[如果您不使用第一级网址作为子类别,例如www.domain.com/18th-and-19th-century,那么您可以使用静态页面]
如果这个答案对你有帮助,那么我会写.htaccess规则