【问题标题】:URL formatting using .htaccess使用 .htaccess 格式化 URL
【发布时间】:2014-08-12 04:30:08
【问题描述】:

如果之后有bill,我想隐藏shop

这些是我的示例网址:

http://mypools.myfiles.com/shop/bill/home.php
http://mypools.myfiles.com/shop/bill/search.php
http://mypools.myfiles.com/shop/bill/index.php

此外,如果我键入以下任何 URL:

http://mypools.myfiles.com/shop/bill
http://mypools.myfiles.com/shop/bill/

我希望它重定向到以下链接:

http://mypools.myfiles.com/shop/bill/home.php

【问题讨论】:

  • 为什么有人会吃掉你的网址?
  • 您的问题存在一些歧义:您想将http://mypools.myfiles.com/bill/home.php 重定向到http://mypools.myfiles.com/shop/bill/home.php(内部)和http://mypools.myfiles.com/shop/bill 重定向到http://mypools.myfiles.com/shop/bill/home.php 内部还是外部?
  • 很抱歉造成混淆。主要要求是从前三个网址中隐藏“商店”(应该适用于所有类似的网址)。如果我输入“mypools.myfiles.com/shop/bill”或“mypools.myfiles.com/shop/bill”,它应该重定向到mypools.myfiles.com/shop/bill/home.php [但最终网址中不会显示商店]。现在清楚了吗?

标签: .htaccess url mod-rewrite pretty-urls


【解决方案1】:

将此代码放入您的DOCUMENT_ROOT/.htaccess 文件中:

RewriteEngine On

RewriteRule ^(bill/.+)$ /shop/$1 [L,NC]

RewriteRule ^shop/bill/?$ /shop/bill/home.php [L,NC]

【讨论】:

  • 以上代码用于将 ....../bill/ 重定向到 .../bill/home.php 或从 uRL 隐藏商店文件夹?
  • 此代码用于处理浏览器中的http://mypools.myfiles.com/shop/search.php URL,内部将重写为http://mypools.myfiles.com/shop/bill/search.php
猜你喜欢
  • 1970-01-01
  • 2017-12-20
  • 1970-01-01
  • 2017-01-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-31
相关资源
最近更新 更多