Apache .htaccess重定向
Im使用Apache和.htaccess文件设置一些重定向。除了域索引外,有没有办法将域中的所有内容重定向到子域 所以重定向Apache .htaccess重定向,apache,.htaccess,redirect,Apache,.htaccess,Redirect,Im使用Apache和.htaccess文件设置一些重定向。除了域索引外,有没有办法将域中的所有内容重定向到子域 所以重定向http://domain.com/*至http://sub.domain.com/* 但是离开http://domain.com/它在哪里 如果有人能帮忙,请提前感谢 您可能希望在主域上允许默认html或php。在这种情况下,以下两条规则应该有效。测试和确认 # Check for non-empty request URI RewriteCond %{REQUEST_U
http://domain.com/*
至http://sub.domain.com/*
但是离开http://domain.com/
它在哪里
如果有人能帮忙,请提前感谢 您可能希望在主域上允许默认html或php。在这种情况下,以下两条规则应该有效。测试和确认
# Check for non-empty request URI
RewriteCond %{REQUEST_URI} (.+)
RewriteRule .* http://sub.domain.com%1 [L,R=301]
# Skip the rewrite for the root of domain.com
RewriteCond %{HTTP_HOST} ^domain[.]com$ [NC]
RewriteCond %{REQUEST_URI} ^(/(index[.](html|php))?)?$
RewriteRule ^(.*)$ - [L]
# Rewrite everything else
RewriteCond %{HTTP_HOST} ^(domain[.]com)$ [NC]
RewriteRule ^(.*)$ http://sub.%1$1 [R=301,QSA,L]
您可能希望在主域上允许默认html或php。在这种情况下,以下两条规则应该有效。测试和确认
# Skip the rewrite for the root of domain.com
RewriteCond %{HTTP_HOST} ^domain[.]com$ [NC]
RewriteCond %{REQUEST_URI} ^(/(index[.](html|php))?)?$
RewriteRule ^(.*)$ - [L]
# Rewrite everything else
RewriteCond %{HTTP_HOST} ^(domain[.]com)$ [NC]
RewriteRule ^(.*)$ http://sub.%1$1 [R=301,QSA,L]
单一重写规则:
# Rewrite if on main domain AND NOT requesting index
RewriteCond %{HTTP_HOST} ^domain[.]com$ [NC]
RewriteCond %{REQUEST_URI} !^(/(index[.](html|php))?)?$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://sub.%1$1 [R=301,QSA,L]
单一重写规则:
# Rewrite if on main domain AND NOT requesting index
RewriteCond %{HTTP_HOST} ^domain[.]com$ [NC]
RewriteCond %{REQUEST_URI} !^(/(index[.](html|php))?)?$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://sub.%1$1 [R=301,QSA,L]
这看起来应该以最简洁的方式完成这项工作——我将在新的domain.com页面构建完成后进行测试,并让您知道。谢谢我终于开始需要这个了,并且已经测试过了。它似乎接近于我所需要的,但它也重写了主(非重定向)页面的css和javascript请求。是否有办法将*.css和*.js从重定向中排除?@mrappleton-我在上面的重写中添加了几个条件-如果文件存在,它将不会重写…这看起来应该以最简洁的方式完成工作-我将在构建新的domain.com页面后进行测试,并让您知道。谢谢我终于开始需要这个了,并且已经测试过了。它似乎接近于我所需要的,但它也重写了主(非重定向)页面的css和javascript请求。有没有办法从重定向中排除*.css和*.js?@mrappleton-我在上面的重写中添加了几个条件-如果文件存在,它将不会重写。。。