URL重写的mod_rewrite [英] Url rewriting mod_rewrite
问题描述
我的网址,如:
page.com/content.php?xname=p&yname=q&zid=1
我想用URL重写改写这个网址是这样的:
page.com/p/q/
注意,不应该在更名为URL'ZID'参数。我知道前pressions被传递进入原始URL。 是否有可能与上述重命名。如果是,如何实现这一目标?
这一次为我工作正常,将改写要求 / P / Q /
到 /content.php?xname=p&yname=q&zid=1
。
选项+了FollowSymLinks -MultiViews
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
重写规则^([^ /] +)/([^ /] +)/ $ content.php的XName = $ 1和; yname = $ 2及ZID = 1 [QSA,L]
-
这条规则是被放置在.htaccess在网站根目录。如果放在其他地方的一些小的调整可能是必需的。
-
这不会重写,如果请求的URL是一个真正的文件或文件夹(我敢肯定,你不想改写图像或其他一些网页 - 我不得不添加这样的条件,因为我不知道是什么你的网站结构)。
I have the url such as:
page.com/content.php?xname=p&yname=q&zid=1
I want to rewrite this url using apache mod_rewrite into something like:
page.com/p/q/
note there should not be 'zid' parameter in renamed url. I know expressions are passed as GET into the original url. Is it possible to rename as above. If yes, How to achieve this?
This one works fine for me and will rewrite request for /p/q/
to /content.php?xname=p&yname=q&zid=1
.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/$ content.php?xname=$1&yname=$2&zid=1 [QSA,L]
This rule is to be placed in .htaccess in website root folder. If placed elsewhere some small tweaking may be required.
It will not rewrite if requested URL is a real file or folder (I'm sure you do not want to rewrite images or some other pages -- I had to add such condition since I do not know what is your website structure is).
这篇关于URL重写的mod_rewrite的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!