的.htaccess URL重写 - 删除的.php去除WWW。转换?ID = 10/10 [英] .htaccess url rewrite - remove .php remove www. convert ?id=10 to /10

查看:451
本文介绍了的.htaccess URL重写 - 删除的.php去除WWW。转换?ID = 10/10的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正如标题所说,我需要一个相当复杂的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]

这篇关于的.htaccess URL重写 - 删除的.php去除WWW。转换?ID = 10/10的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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