【发布时间】:2021-04-05 05:44:05
【问题描述】:
以下是我的 HTACCESS,我在其中使用以下规则重定向我的网站。
https://rosterelf.com 将被重定向到https://www.rosterelf.com/
http://www.rosterelf.com 将被重定向到https://www.rosterelf.com
rosterelf.com 将被重定向到https://www.rosterelf.com/
所以基本上它会检查 url 是否没有 www 或 https 然后它会直接使用它。这对我来说很好用。
但是,现在我想用 .com.au 重定向我的所有网址 ..
我应该能够在与上述相同的条件下将https://www.rosterelf.com.au/ 重定向到https://www.rosterelf.com/。通过检查 https 或 非 www 到 www。
我尝试过各种代码,例如
RewriteCond %{HTTP_HOST} =m.somesite.com.au
RewriteRule (.*) http://www.somesite.com.au/$1 [R,L]
和其他人通过添加我现有的 htaccess 文件,但它在少数情况下不起作用,比如在我的内页中......或没有 https。这是我当前的 htaccess 文件的样子。
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
##
## You may need to uncomment the following line for some hosting environments,
## if you have installed to a subdirectory, enter the name here also.
##
# RewriteBase /
##
## Uncomment following lines to force HTTPS.
##
# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{SERVER_NAME}/$1 [L,R=301]
# CONDITIONS FOR ONLY LIVE SITE STARTS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
# CONDITIONS FOR ONLY LIVE SITE ENDS
##
## Black listed folders
##
RewriteRule ^bootstrap/.* index.php [L,NC]
RewriteRule ^config/.* index.php [L,NC]
RewriteRule ^vendor/.* index.php [L,NC]
RewriteRule ^storage/cms/.* index.php [L,NC]
RewriteRule ^storage/logs/.* index.php [L,NC]
RewriteRule ^storage/framework/.* index.php [L,NC]
RewriteRule ^storage/temp/protected/.* index.php [L,NC]
RewriteRule ^storage/app/uploads/protected/.* index.php [L,NC]
##
## White listed folders
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} !/.well-known/*
RewriteCond %{REQUEST_FILENAME} !/storage/app/uploads/public/.*
RewriteCond %{REQUEST_FILENAME} !/storage/app/media/.*
RewriteCond %{REQUEST_FILENAME} !/storage/app/resized/.*
RewriteCond %{REQUEST_FILENAME} !/storage/temp/public/.*
RewriteCond %{REQUEST_FILENAME} !/themes/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/plugins/.*/(assets|resources)/.*
RewriteCond %{REQUEST_FILENAME} !/modules/.*/(assets|resources)/.*
RewriteRule !^index.php index.php [L,NC]
##
## Block all PHP files, except index
##
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} \.php$
RewriteRule !^index.php index.php [L,NC]
##
## Standard routes
##
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
正如您在上面的 htaccess 中看到的,我使用以下 3 行代码将非 www 重定向到 www 并将 http 重定向到 https ..
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
现在我的问题是,我怎样才能使所有现有条件能够将 .com.au 重定向到 .com ?
有人可以指导我吗..
谢谢
【问题讨论】:
标签: apache .htaccess redirect mod-rewrite url-rewriting