简体   繁体   English

Mod重写和动态URL

[英]Mod rewrite and dynamic URLs

i know this is a common question but i cannot figure this one out. 我知道这是一个常见问题,但我无法弄清楚。

I have the following URL: 我有以下网址:

http://buildsanctuary.com/viewbuild.php?id=3&title=this_is_a_title&page=1

What i wish is the URL to be: 我希望网址是:

http://buildsanctuary.com/viewbuild/3/this_is_a_title/1

Normally for mod rewrites i would send the user to the link i want and let htaccess do all the work. 通常对于mod重写,我会将用户发送到我想要的链接,并让htaccess完成所有工作。

So in this case i have tried linking the users to the preferred URL style and rewriting the URL but to no avail. 因此,在这种情况下,我尝试将用户链接到首选的URL样式并重写URL,但无济于事。

Any help on how i should be handling this? 我应该如何处理任何帮助? I want to send the users to the preffered URL but then can i use htaccess to allow me to process the page and URL $_GET information in the same way as the normal dynamic URL? 我想将用户发送到首选URL,但是我可以使用htaccess允许我以与普通动态URL相同的方式处理页面和URL $ _GET信息吗?

I have tried the mod rewrite generators etc but nothing works. 我已经尝试了mod重写生成器等,但是没有任何效果。

This is what the gens have given me: 这是各族给我的:

RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.php$ /viewbuild.php?id=$1&title=$2&page=$3 [L]

Thanks. 谢谢。

Fix the generator rule: 修正生成器规则:

RewriteRule ^viewbuild/([^/]*)/([^/]*)/([^/]*)\.php$ /viewbuild.php?id=$1&title=$2&page=$3 [L,QSA]

However, I would do it this way: 但是,我会这样做:

RewriteRule ^([^/]*)/(.*) /$1.php/$2 [L]

and then map what you get in $_SERVER['PATH_INFO'] to you preference in PHP. 然后将您在$_SERVER['PATH_INFO']获得的内容映射到PHP中的首选项。

Put this code in your DOCUMENT_ROOT/.htaccess file: 将此代码放在您的DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([\w-]+)/([^/]+)/([^/]+)/([^/]+)/?$ /$1.php?id=$2&title=$3&page=$4 [L,QSA]

Should do the trick 应该做的把戏

^viewbuild/([0-9]+)/([a-z_]+)/-([0-9]+)/?$ viewbuild.php?id=$1&title=$2&page=$3 [NC,L] ^ viewbuild /([[0-9] +)/([a-z _] +)/-([0-9] +)/?$ viewbuild.php?id = $ 1&title = $ 2&page = $ 3 [NC,L ]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM