繁体   English   中英

htacces url重写条件

[英]htacces url rewriting with rewrite condition

目前,我有一个可以通过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页面时,我认为这里需要一些条件,但无法理解该如何进行

提前致谢

尝试

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

您已在同一目录级别上编写了所有url,因此无法编写动态.htaccess规则。 您需要在所有要访问不同php页面的不同类型的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

像以上页面一样,您可以使用以下样式的url

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

要么

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这样的子类别使用第一级URL,则可以用于静态页面]

如果这个答案对您有所帮助,那么我将编写.htaccess规则

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM