Apache 修改现有的.htaccess,使其忽略子域

Apache 修改现有的.htaccess,使其忽略子域,apache,.htaccess,Apache,.htaccess,我已经准备好了下面的.htaccess文件,虽然我知道它远没有达到最佳状态(而且可能有点畏缩),但它可以正常工作 # Prevents public viewing of .htaccess file <Files .htaccess> order allow,deny deny from all </Files> # Custom 404 page ErrorDocument 404 https://www.domain.com/404/ # Turn on rew

我已经准备好了下面的.htaccess文件,虽然我知道它远没有达到最佳状态(而且可能有点畏缩),但它可以正常工作

# Prevents public viewing of .htaccess file
<Files .htaccess>
order allow,deny
deny from all
</Files>

# Custom 404 page
ErrorDocument 404 https://www.domain.com/404/

# Turn on rewriting and set rewriting base
RewriteEngine On
RewriteBase /

# Force WWW
RewriteCond %{HTTP_HOST} !^$
RewriteCond %{HTTP_HOST} ^([^.]+)\.([a-z]{2,4})$ [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

# Force WWW and HTTPS
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L]

# Remove .php extension
RewriteRule ^(properties)/(all|location1|location2|location3)/(all|1|2|3|4|5|6|7|8|9)/(asc|desc) $1.php?location=$2&bedrooms=$3&sort-by=$4
RewriteRule ^(properties)/(all|location1|location2|location3)/(all|1|2|3|4|5|6|7|8|9) $1.php?location=$2&bedrooms=$3
RewriteRule ^(properties)/(all|location1|location2|location3) $1.php?location=$2
RewriteRule ^(view-property)/(.*)/(print-view) $1.php?id=$2&print=true
RewriteRule ^(view-property)/(.*)/ $1.php?id=$2
RewriteRule ^(.*)/$ $1.php
但不幸的是,所有这些都不起作用。使用
.htaccess
文件并不是我的强项,所以如果有人能提供任何帮助,那就太好了


另外,新网站是由Laravel 5.3提供动力的,所以当我们上线时,我将不再试图改写规则(那些在底部的规则)

您的首要规则必须更改为此,才能删除目标URL中的硬编码域名:

# Turn on rewriting and set rewriting base
RewriteEngine On
RewriteBase /

# Force WWW and HTTPS
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

# Remove .php extension and rest of the rewrite rules

我已按上述详细规定更改了规则,同时现场继续按预期工作,登台URL
staging.domain.com
继续直接重定向到
https://www.domain.com
。使用
curl
返回以下内容:
301永久移动文档已移动。

您的.htaccess中是否仍有重定向规则?我的答案没有重定向到
https://www.tynesidelettings.com/
否,现在我的
.htaccess
文件中唯一的重写规则就是上面的回答。这可能是我们的服务器上发生重定向的原因吗?是的,将我的
.htaccess
重命名为
.htaccess.bak
并使用
curl
我得到了相同的响应。我会和我的主机提供商联系,看看服务器端出了什么问题。谢谢你的帮助!
# Turn on rewriting and set rewriting base
RewriteEngine On
RewriteBase /

# Force WWW and HTTPS
RewriteCond %{HTTP_HOST} !^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L,NE]

# Remove .php extension and rest of the rewrite rules