基本mod_rewrite的问题 [英] basic mod_rewrite question
问题描述
我想写一个规则,说:
xyz.com/hotels_in_someplace将直接向xyz.com/test.php?place=someplace
xyz.com/hotels_in_someplace will direct to xyz.com/test.php?place=someplace
使用下在我的htaccess
by using the following in my htaccess
RewriteEngine On
RewriteBase /
RewriteRule ^hotels_in_([a-z]+)$ test.php?place=$1 [L]
但它不工作,我不能找出原因,我运行一个瓦帕服务器作为开发。当我试图运行xyz.com/test.php?place=someplace(不包括在目录中的htaccess的),它的工作原理,但我怀疑有什么东西我的原则是错误的。
but its not working and I cant figure out why, I am running a wamp server as a dev. when i tried to run xyz.com/test.php?place=someplace (without the htaccess in the directory) it works but I suspect there's something my rule which is wrong.
补充: 哎呦....我愚蠢的屁股的错误,启用了mod_rewrite wasnt ...
additional: whoops....my dumb ass mistake, mod_rewrite wasnt enabled...
推荐答案
更新:我之前,所以我一点关于斜线为空没有注意到的问题的RewriteBase。然而,重写规则并不在我的机器上运行。
Update: I didn't notice the RewriteBase in the question before so my point about the leading slash is null. However the RewriteRule does work on my machine.
尝试:
RewriteRule ^hotels_in_([a-z]+)$ /test.php?place=$1 [L]
的路径test.php的需要斜线。你想你在做什么,你将被重定向到xyz.com/path/to/web/docs/on/machine/test.php~~V并重写的方式,那不是。 :)
The path to test.php needs the leading slash. The way you are doing the rewrite you will be redirected to xyz.com/path/to/web/docs/on/machine/test.php and thats not what you want. :)
另外,如果你是你,包括你的测试斜线。
Also if you are you including a trailing slash in your test.
以上规则不匹配 xyz.com/hotels_in_someplace /
。
要匹配领先的斜线这应该工作:
To match the leading slash this should work:
RewriteRule ^hotels_in_([a-z]+)/?$ /test.php?place=$1 [L]
这篇关于基本mod_rewrite的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!