简体   繁体   English

.htacces如果找不到文件或文件夹,则重定向到新域

[英].htacces redirect to new domain if file or folder not found

if my site is domain.com and if i go to domain.com/1 and the folder 1 dont exist can i redirect via .htacces to domain2.com/1 如果我的网站是domain.com,并且如果我转到domain.com/1并且文件夹1不存在,我可以通过.htacces重定向到domain2.com/1

if file or folder exist i like to show that file or folder but if not exist then to redirect to new domain 如果文件或文件夹存在,我想显示该文件或文件夹,但如果不存在,则重定向到新域

example: if file.html dont exist in my server then 示例:如果我的服务器中不存在file.html,则

example.com/file.html redirect to newdomain.com/file.html example.com/file.html重定向到newdomain.com/file.html

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ newdomain.com/$1     

You need to include the http:// bit: 您需要包含http://位:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://newdomain.com/$1 [L,R]

otherwise, mod_rewrite will interpret that as a URL or file path and attempt to look for a directory called "newdomain.com". 否则,mod_rewrite会将其解释为URL或文件路径,并尝试查找名为“ newdomain.com”的目录。 If you want the redirect to be permanent, change the R flag to R=301 . 如果您希望重定向是永久的,请将R标志更改为R=301

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM