Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 试图覆盖htaccess文件中的多个重定向条件_.htaccess_Url Redirection_Http Redirect - Fatal编程技术网

.htaccess 试图覆盖htaccess文件中的多个重定向条件

.htaccess 试图覆盖htaccess文件中的多个重定向条件,.htaccess,url-redirection,http-redirect,.htaccess,Url Redirection,Http Redirect,我试图编写一个htaccess文件,该文件涵盖了我需要的所有基础,但我有很多非常具体的操作要涵盖 我有三个域名:.com.co.uk和.london,我希望所有流量都以.london结束,但到.london的流量除外,它必须重定向到特定的mysite/london.php页面 所以我所有的条件都是: force www prefix force https remove extensions force .co.uk to .com domain force any .london traffi

我试图编写一个htaccess文件,该文件涵盖了我需要的所有基础,但我有很多非常具体的操作要涵盖

我有三个域名:.com.co.uk和.london,我希望所有流量都以.london结束,但到.london的流量除外,它必须重定向到特定的mysite/london.php页面

所以我所有的条件都是:

force www prefix
force https
remove extensions
force .co.uk to .com domain
force any .london traffic to specific /london page
到目前为止,我已经:

# Force WWW prefix
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# Force SSL
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# Remove .php extension
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]
所以我需要加上最后两个条件

force .co.uk to .com domain
force any .london traffic to specific /london page
但是我很难让所有的东西都在一起工作

编辑:

仍然在努力使所有条件协同工作,因此为了清晰起见,在这里添加一些示例

www.example.com->

->

->

www.example.co.uk->

->

->

www.example.london->

->

->

因此,所有URL都必须添加“www”,仅添加.com域,强制使用https,删除php扩展


我已经尝试了数百个代码片段和组合,但无法同时满足所有条件。

您可以使用以下规则:

# force .co.uk to .com domain
RewriteCond %{HTTP_HOST} ^(www\.)?\.example\.co\.uk$
RewriteRule ^ https://www.example.com%{REQUEST_URI} [NE,L,R=301]

# force any .london traffic to specific /london page
RewriteCond %{HTTP_HOST} ^(www\.)?example\.london$
# this line is important to avoid Redirect loop error
RewriteCond %{REQUEST_URI} !/london/page
RewriteRule ^ /london/page%{REQUEST_URI} [L,R]

# Force WWW prefix
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# Force SSL
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]

# Remove .php extension
RewriteCond %{THE_REQUEST} ^GET\ /[^?\s]+\.php
RewriteRule (.*)\.php$ /$1/ [L,R=301]