.htccess 301 重定向域、https、www 和文件扩展名


.htccess 301 redirect for domains, https, www, and file extention

我有几个域名,最近更新了我的网站,以便从单个文件(index.php(运行。请求 URI 除了没有.php之外是相同的。我的主机是GoDaddy linux Unlimited(是的...(。

我需要我的 .htaccess 来重定向/重写以下内容

  • 将 domain1.com 重定向到 www.primary.com
  • 将 www.domain1.com 重定向到 www.primary.com
  • 将 domain2.com 重定向到 www.primary.com
  • 将 www.domain2.com 重定向到 www.primary.com
  • 强制 https://
  • 强制万维网。
  • 从任何请求中删除.php(/marketing/cost.php 到/marketing/cost(
  • 删除尾部斜杠

我当前使用以下代码将所有请求传递到索引.php

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index'.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

索引.php文件处理所有请求。基于 ($_SERVER['REQUEST_URI']( 索引.php从数据库加载内容。

我知道建议使用尾随斜杠,但宁愿不这样做;我认为 domain.com/sec/nom?x=23 看起来比 domain.com/sec/nom/?x=23


我尝试了 .htaccess 中的一些变体,并在本地工作,但不是在 GoDaddy 上。

像这样:

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www'.primary'.com$ [NC,OR]
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.primary.com%{REQUEST_URI} [L,NE,R=302]
RewriteCond %{THE_REQUEST} 's/+(.+?)'.php['s?] [NC]
RewriteRule ^ /%1 [R=302,L]
## Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+?)/$ /$1 [NE,R=302,L]
RewriteRule ^index'.php$ - [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]