htaccess的重写规则的扁平链接 [英] .htaccess RewriteRule for Flat Links

查看:120
本文介绍了htaccess的重写规则的扁平链接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是pretty的新使用重写规则,所以我可能失去了一些东西明显,但我有一个PHP脚本,需要URL变量是这样的:

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:

{baseurl}properties.php?prop=Property-Name

我想创建的规则集,使任何人谁的类型在这个脚本名/变量组合将他们的URL改写为:

I would like to create RewriteRules so that anyone who types in this script name/variable combo would have their URL rewritten to:

{baseurl}/properties/Property-Name

除了确保任何人谁在平坦的链接URL类型,实际上是调用与正确的变量名和值的脚本。

As well as ensuring that anyone who types in the flat-link url, actually calls the script with the right variable name and value.

我已经提到此链接,我已经找到相关主题:

I have been referring to this link and I have found related threads:

mod_rewrite的扁平链接

<一个href="http://stackoverflow.com/questions/4718652/mod-rewrite-trouble-want-to-direct-from-to-a-flat-link-nothing-seems-to-work">Mod_rewrite麻烦?:想从直接=到平面的链接,似乎没有任何工作

不过,我明明做错了什么,因为我不能让这个网址的工作就是我想要的。我目前正在使用下面的code,这似乎什么也不做(从URL重写一边包含www,并重定向到站点根目录请求的index.php):

But, I am obviously doing something wrong, as I cannot get this URL to work the way I want. 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):

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. Again, I am likely doing something ridiculous. Can someone please explain what I am doing wrong?

感谢您的帮助。

推荐答案

目前看一眼,看来,你忘了,包括对你的日常EX pression的仪表板和你包括斜线。而使用这样的:

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

这篇关于htaccess的重写规则的扁平链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆