重定向的站点根目录使用的.htaccess子目录

编程入门 行业动态 更新时间:2024-10-19 21:30:47
本文介绍了重定向的站点根目录使用的.htaccess子目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我的一个网站拥有所有存储在一个子目录中的文件。 previously,我使​​用301重定向发送从 site/specific/page 游客 site/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/specific/page to site/subdirectory/specific/page.

我现在用这样的:

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

这意味着URL是清洁的。然而,有没有一种方法,使htaccess的重定向使用子目录清洁网址的人吗?也就是说,如果有人去 site/subdirectory/specific/page ,有没有办法让网址 site/specific/page ,同时显示来自内容 site/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/subdirectory/specific/page, is there a way to make the URL site/specific/page, while showing the content from site/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子目录

本文发布于:2023-11-01 02:09:33,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1547943.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:子目录   根目录   重定向   站点   htaccess

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!