正如标题所说,我需要一个相当复杂的URL重写机制的web应用程序的的.htaccess规则。 我搜索了很多,现在和不同的重写规则试图百家。
As the title says, I need a quite complex url rewrite mechanism for a web-app as .htaccess rule. I've searched quite a lot now and tried hundred of different rewrite rules.
所以,基本上这就是我需要: 用户进入: http://www.site.com/product.php?id=12 服务器应该重定向到: http://site.com/product/12
So, basically this is what I need: User goes to: http://www.site.com/product.php?id=12 Server should redirect to: http://site.com/product/12
在要提: 并非所有的网页都附加标识的。照片 所以,我也有: http://www.site.com/some/page.php 然后应重定向到: http://site.com/some/page
Once thing to mention: not all pages do append id's. So I also have: http://www.site.com/some/page.php which then should redirect to: http://site.com/some/page
或 http://site.com/anotherone.php 为 http://site.com/anotherone
您帮助很多AP preciated并感谢您很多提前对您有所帮助!
You help is much appreciated and thank you a lot in advance for you help!
推荐答案
我supose你,previously有这个的mod_rewrite规则激活:
I supose that you, previously have this mod_rewrite rule active:
用户进入 http://site.com/product/12 并在浏览器中显示这个URL,并internaly,只有internaly,服务器服务 http://www.site.com /product.php?id=12
Users goes to http://site.com/product/12 and in the browser is showed this URL, and internaly, and only internaly, server serve http://www.site.com/product.php?id=12
把第一的RewriteCond和规则这样的:
Put the first RewriteCond and Rule this:
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(w+).php?id=(d*)$ /$1/$2 [R=301]
和添加另一个删除的.php时的.php结束
And add another to remove the .php when ends with .php
RewriteCond %{ENV:REDIRECT_STATUS} !200
RewriteRule ^(w+).php$ /$1 [R=301]
相关推荐
最新文章