htaccess的从根重定向到子文件夹,然后屏蔽网址是什么? [英] htaccess redirect from root to subfolder and then mask the url?

查看:115
本文介绍了htaccess的从根重定向到子文件夹,然后屏蔽网址是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

两件事情:

首先 - 我有位于一个文件夹命名为V2网站的第2版,我想重定向任何流量不是V2文件夹的孩子,www.example.com/~~V V2

旧址位于根是在iWeb中创建和拥有子文件夹和子子文件夹了很多。

所以:

www.example.com/v2 =新网站

www.example.com/Page.html

www.example.com/category/Page.html

ww.example.com/category/subcategory/Page.html =什么,我需要重定向所有的通用例子。

第二,然后我不知道这是可能的,我想隐藏/ V2 / URL中,让游客只会看到www.example.com/page即使他们实际上在www.example.com/v2/page

链接很难coded到v2的文件夹,像这样< A HREF = V2 / contact.html >

任何帮助最AP preciated。我花了几个小时试图弄清楚这一点,但我只是刚刚了解htaccess以及定期EX pressions,和我完全糊涂了。

太感谢了!

解决方案

 的RewriteCond%{REQUEST_URI}!^ V2 /
重写规则^(。*)V2 / $ 1 [L]
 

Two things:

Firstly - I have version 2 of a website located in a folder named v2, and I want to redirect any traffic that is NOT a child of the v2 folder, to www.example.com/v2

The old site located in the root was created in iWeb and has a LOT of subfolders and sub-subfolders.

So:

www.example.com/v2 = New site

www.example.com/Page.html

www.example.com/category/Page.html

ww.example.com/category/subcategory/Page.html = All generic examples of what I need to redirect.

Secondly, and I don't know if this is possible, I want to hide /v2/ in the URL, so that visitors will just see www.example.com/page even though they are actually on www.example.com/v2/page

Links are hardcoded to the v2 folder, like so <a href="v2/contact.html">

Any help is MOST appreciated. I've spent hours trying to figure this out, but I'm only just learning about htaccess and regular expressions, and am totally confused.

Thanks so much!

解决方案

RewriteCond %{REQUEST_URI} !^v2/
RewriteRule ^(.*)$ v2/$1 [L] 

这篇关于htaccess的从根重定向到子文件夹,然后屏蔽网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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