htaccess重定向根和子域(htaccess redirect for root and subdomain)

编程入门 行业动态 更新时间:2024-10-28 21:30:31
htaccess重定向根和子域(htaccess redirect for root and subdomain)

我想更改我的网站的URL结构,我需要进行一些重定向,基本上我想要:

www.root.com/folder/second_folder/file.php重定向到folder.root.com/second_folder/file.php

反正我是否可以强制将第一个网址重定向到子网址网址? 我还有一些特定的根URL,我想重定向到子域中的特定文件夹。

我尝试了各种方法,到目前为止没有任何工作,但只能将我的htaccess文件放在根文件夹中。 如果我将它放在我的子域文件夹中,那么它会将它们全部分开。

谢谢。

I want to change the URL structure of my site, and I need to make some redirects, basically i want:

www.root.com/folder/second_folder/file.php to redirect to folder.root.com/second_folder/file.php

Is there anyway that I could force to redirect the first url, to the subdomain url? I also have some specific root URL's that I want to redirect to specific folders in the subdomain.

I tried various ways and nothing works so far, but only by placing my htaccess file in the root folder. If I place it in my subdomain folder, then it breaks all together.

Thank you.

最满意答案

将此代码放在DOCUMENT_ROOT/.htaccess文件中:

RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?root\.com$ RewriteRule ^([^/]+)/(.+?\.php)$ http://$1.root.com/$2 [L,R=301,NE]

Place this code in your DOCUMENT_ROOT/.htaccess file:

RewriteEngine On RewriteCond %{HTTP_HOST} ^(www\.)?root\.com$ RewriteRule ^([^/]+)/(.+?\.php)$ http://$1.root.com/$2 [L,R=301,NE]

更多推荐

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

发布评论

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

>www.elefans.com

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