【发布时间】:2013-10-13 12:47:46
【问题描述】:
我正在寻找可以转换以下网址的一系列 .htaccess 语句
http://mysite.com/product to http://mysite.com/product.php
http://mysite.com/product/55 to http://mysite.com/product.php?id=55
http://mysite.com/category/38 to http://mysite.com/category.php?id=38
http://mysite.com/resources/car/19 to http://mysite.com/resources/car.php?id=19
http://mysite.com/resources/car/19?color=red&year=2013 to http://mysite.com/resources/car.php?id=19&color=red&year=2013
换句话说,在我的网站中呈现 php 文件时,我想删除 .php 扩展名。如果 url 以数字结尾,那么我想将其作为 id 查询字符串参数传递。我还想将所有常规查询字符串参数传递给我的 php 文件,例如 color 和 year。
我不确定如何构建这样的 .htaccess 文件。
附加说明
我目前正在使用 hte following,但它没有考虑带有数字的网址,并将其作为 id
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteCond %{QUERY_STRING} (.*)
RewriteRule . %{REQUEST_FILENAME}.php?%1 [L]
如果我可以在第二行替换 REQUEST_FILENAME 中的尾随数字,那就太好了。
【问题讨论】:
-
您是否尝试过四处搜索?可能这有帮助! stackoverflow.com/questions/16230422/…
-
大家好,我试着四处搜索,但没有找到我要找的东西。我更新了我的问题以显示我当前的重写规则。