Htaccess www 到非 www 但保持 url 完整
Htaccess www to non-www but keep the url intact
我觉得这很简单,但我就是想不通。
我有一个像 https://www.example.com
这样的域
我想改写成https://example.com
行得通。但是我也在重写其他 urls,比如 https://www.example.com/privacy
如果我也尝试重写这些,用户总是会被重定向到 https://example.com/privacy.php
如何防止我的服务器显示实际文件名而不是重写的文件名url?
我的代码如下所示:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^checkout checkout.php [L]
RewriteRule ^imprint imprint.php [L]
RewriteRule ^privacy privacy.php [L]
RewriteRule ^terms terms.php [L]
RewriteRule ^allergy allergy.php [L]
RewriteRule ^nutrition nutrition.php [L]
RewriteRule ^order/([A-Z]*)?$ confirmation.php?lang=&id= [L,QSA]
感谢任何帮助。
此致
这样说:
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^(checkout|imprint|privacy|terms|allergy|nutrition)/?$ .php [L]
RewriteRule ^order/([a-z]+)/?$ confirmation.php?lang=&id= [L,QSA,NC]
确保在清除浏览器缓存后进行测试。问题似乎是由于您的模式没有使用端锚。
我已将您的多个相似规则合并为一个规则。
我觉得这很简单,但我就是想不通。
我有一个像 https://www.example.com
这样的域我想改写成https://example.com
行得通。但是我也在重写其他 urls,比如 https://www.example.com/privacy
如果我也尝试重写这些,用户总是会被重定向到 https://example.com/privacy.php
如何防止我的服务器显示实际文件名而不是重写的文件名url?
我的代码如下所示:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^checkout checkout.php [L]
RewriteRule ^imprint imprint.php [L]
RewriteRule ^privacy privacy.php [L]
RewriteRule ^terms terms.php [L]
RewriteRule ^allergy allergy.php [L]
RewriteRule ^nutrition nutrition.php [L]
RewriteRule ^order/([A-Z]*)?$ confirmation.php?lang=&id= [L,QSA]
感谢任何帮助。
此致
这样说:
Options -MultiViews
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L,NE]
RewriteRule ^(checkout|imprint|privacy|terms|allergy|nutrition)/?$ .php [L]
RewriteRule ^order/([a-z]+)/?$ confirmation.php?lang=&id= [L,QSA,NC]
确保在清除浏览器缓存后进行测试。问题似乎是由于您的模式没有使用端锚。
我已将您的多个相似规则合并为一个规则。