重定向的站点根目录使用的.htaccess子目录 [英] Redirecting root of site to subdirectory using .htaccess

查看:176
本文介绍了重定向的站点根目录使用的.htaccess子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的一个网站拥有所有存储在一个子目录中的文件。 previously,我使​​用301重定向发送从 site.com/specific/page 游客 site.com/subdirectory/specific/page

A site of mine has all the files stored in a subdirectory. Previously, I used a 301 redirect to send visitors from site.com/specific/page to site.com/subdirectory/specific/page.

我现在用这样的:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteCond %{REQUEST_URI} !^/subdirectory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subdirectory/$1
RewriteCond %{HTTP_HOST} ^(www.)?site.com$
RewriteRule ^(/)?$ subdirectory/index.php [L]

这意味着URL是清洁的。然而,有没有一种方法,使htaccess的重定向使用子目录清洁网址的人吗?也就是说,如果有人去 site.com/subdirectory/specific/page ,有没有办法让网址 site.com/specific/page ,同时显示来自内容 site.com/subdirectory /特定/页

This means the URL is cleaner. However, is there a way to make the htaccess redirect people using the subdirectory to the cleaner URL? i.e. if someone goes to site.com/subdirectory/specific/page, is there a way to make the URL site.com/specific/page, while showing the content from site.com/subdirectory/specific/page?

推荐答案

是的,BUIT而不是改写,妍会重定向。

Yes, buit instead of rewriting, youn would redirect..

RedirectMatch 301 "^/subdirectory/(.*)" "/$1"

这样一来,如果他们直接命中任​​何子目录中,他们将被重定向到更清洁的网址,你的规则的设置将在踢。

That way, if they hit any subdirectory directly, they will be redirected to the cleaner URL, where your rules above will kick in.

这篇关于重定向的站点根目录使用的.htaccess子目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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