如何从URL使用htaccess的删除文件夹名称 [英] how to remove folder name from url using htaccess

查看:312
本文介绍了如何从URL使用htaccess的删除文件夹名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从改变网址:

  http://domain.com/Portfolios/iPhone/app
 

要:

  http://domain.com/iPhone/app
 

和同样像所有网址:

  domain.com/Portfolios/iPad/app
 

要:

  domain.com/iPad/app
 

和来自:

  domain.com/Portfolios/xyz/app
 

要:

  domain.com/xyz/app
 

我已经尝试了很多,但没有什么工作适合我,所以请帮助我。

当我需要帮助,为什么任何哥们倒投票吧,如果你知道答案,然后回答吧。

更新

 < IfModule mod_rewrite.c>
   RewriteEngine叙述上
   重写规则^投资组合(/.* |)$ $ 1 [L,NC]
< / IfModule>
 

解决方案

启用的mod_rewrite 的.htaccess 的httpd.conf ,然后把这个code在的.htaccess DOCUMENT_ROOT 目录

 选项+了FollowSymLinks -MultiViews
#开启mod_rewrite的上
RewriteEngine叙述上
的RewriteBase /

重写规则^公文包/(.*)$ / $ 1 [L,NC,R]
 

说明:以上规则匹配的URL图案与公文包启动并具有财产以后像 /公文包/ XYZ /应用看跌 XYZ /应用 $ 1 。它使一个外部重定向 / $ 1 / XYZ /应用程序

这些都是使用的标志:

  L  - 最后
NC  - 忽略(无)情况相比,
的R  - 外部重定向(与302) - 可以被改变为R = 301
 

I want to change the URL from:

http://domain.com/Portfolios/iPhone/app

To:

http://domain.com/iPhone/app

And same for all URLs like:

domain.com/Portfolios/iPad/app

To:

domain.com/iPad/app

And from:

domain.com/Portfolios/xyz/app

To:

domain.com/xyz/app

I have tried a lot but nothing is working for me, so please help me.

When I need help why any buddy down voting it, if you know the answer then answer it.

Update

<IfModule mod_rewrite.c>
   RewriteEngine on
   RewriteRule ^Portfolios(/.*|)$ $1 [L,NC]  
</IfModule>

解决方案

Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:

Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /

RewriteRule ^Portfolios/(.*)$ /$1 [L,NC,R]

Explanation: Above rules is matching URL patter that starts with Portfolios and have somthing like /Portfolios/xyz/app and puts xyz/app in $1. It makes an external redirection to /$1 i.e. /xyz/app.

These are the flags used:

L  - Last
NC - Ignore (No) Case comparison
R  - External redirection (with 302) -- can be changed to R=301

这篇关于如何从URL使用htaccess的删除文件夹名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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