[英].htaccess RewriteRule for Flat Links
I am pretty new to using the RewriteRule, so I am likely missing something obvious, but I have a PHP script that takes URL variables like this: 我对使用RewriteRule很新,所以我可能会遗漏一些明显的东西,但我有一个PHP脚本,它采用如下的URL变量:
{baseurl}properties.php?prop=Property-Name
I would like to create RewriteRules so that anyone who types in this script name/variable combo would have their URL rewritten to: 我想创建RewriteRules,以便任何输入此脚本名称/变量组合的人都会将其URL重写为:
{baseurl}/properties/Property-Name
As well as ensuring that anyone who types in the flat-link url, actually calls the script with the right variable name and value. 除了确保输入flat-link url的任何人,实际上使用正确的变量名称和值调用脚本。
I have been referring to this link and I have found related threads: 我一直在指这个链接 ,我找到了相关的主题:
Mod_rewrite flat links Mod_rewrite扁平链接
Mod_rewrite trouble: Want to direct from ?= to a flat link, nothing seems to work Mod_rewrite麻烦:想要从?=指向扁平链接,似乎没什么用
But, I am obviously doing something wrong, as I cannot get this URL to work the way I want. 但是,我显然做错了,因为我无法让这个URL按照我想要的方式工作。 I am currently using the following code, which appears to do nothing (aside from rewriting the URL to include the www, and redirect requests for index.php to the site root):
我目前正在使用以下代码,它似乎什么都不做(除了重写URL以包含www,并将index.php的请求重定向到站点根目录):
RewriteEngine ON
RewriteCond %{HTTP_HOST} ^baseurl.com$ [NC]
RewriteRule ^(.*)$ http://www.baseurl.com/$1 [R=301,L]
RewriteRule ^index.php / [R=301,L]
RewriteRule ^properties/([0-9A-Za-z]+)/$ /properties.php?prop=$1
The issue is clearly with the last RewriteRule, assuming nothing above is affecting it. 问题显然是最后的RewriteRule,假设上面没有任何影响它。 Again, I am likely doing something ridiculous.
再说一遍,我可能会做一些荒谬的事情。 Can someone please explain what I am doing wrong?
有人可以解释一下我做错了什么吗?
Thanks for your help. 谢谢你的帮助。
At a quick glance, it appears that you forgot to include the dash in your regular expression and you included trailing slash. 快速浏览一下,您似乎忘记在正则表达式中包含短划线,并且包含尾部斜杠。 Use this instead:
请改用:
RewriteRule ^properties/([0-9A-Za-z-]+)$ /properties.php?prop=$1
If you look at your rule ^properties/([0-9A-Za-z]+)/$
you see that it needs to end with a forward slash. 如果你查看你的规则
^properties/([0-9A-Za-z]+)/$
你会发现它需要以正斜杠结束。 You can either remove that or make it optional like ^properties/([0-9A-Za-z]+)/?$
. 您可以删除它或使其可选,如
^properties/([0-9A-Za-z]+)/?$
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.