[英]htaccess redirect all links except base url
I want to redirect all links from my site except the home url to subdirectory. 我想将除主页URL以外的所有链接从我的网站重定向到子目录。
Example: 例:
www.example.com
should remain www.example.com
www.example.com
应该保留为www.example.com
www.example.com/someurl
should redirect to www.example.com/sub/someurl
www.example.com/someurl
应该重定向到www.example.com/sub/someurl
www.example.com/someurl/anothermore
should redirect to www.example.com/sub/someurl/anothermore
www.example.com/someurl/anothermore
应该重定向到www.example.com/sub/someurl/anothermore
Edit: I am currently working on a subdirectory so currently its www.example.com/main/someurl
to redirect to www.example.com/main/sub/someurl
编辑:我当前正在子目录上,所以当前其
www.example.com/main/someurl
重定向到www.example.com/main/sub/someurl
To redirect everything to the /sub
subdirectory, except the root then you can do something like the following at the top of your .htaccess
file in the document root using mod_rewrite: 要将所有内容重定向到
/sub
子目录(除了根目录),您可以使用mod_rewrite在文档根目录的.htaccess
文件顶部执行以下操作:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/sub/
RewriteRule !^(index\.php)?$ /sub%{REQUEST_URI} [R,L]
The above states that if the request is not /
(or /index.php
) and does not start /sub/
(the RewriteCond
directive) then redirect to /sub/<suburl>
. 上面指出,如果请求不是
/
(或/index.php
)并且没有启动/sub/
( RewriteCond
指令),则重定向到/sub/<suburl>
。
Edit: I am currently working on a subdomain so currently its
www.example.com/main/someurl
to redirect towww.example.com/main/sub/someurl
编辑:我目前正在子域上工作,因此当前将其
www.example.com/main/someurl
重定向到www.example.com/main/sub/someurl
That's a subdirectory, not a "subdomain". 那是一个子目录,而不是“子域”。 (?)
(?)
If this is the case then move these directives to a /main/.htaccess
file and change them to read: 如果是这种情况,请将这些指令移至
/main/.htaccess
文件并将其更改为:
RewriteCond %{REQUEST_URI} !^/main/(index\.php)?$
RewriteCond %{REQUEST_URI} !^/main/sub/
RewriteRule (.*) /main/sub/$1 [R,L]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.