简体   繁体   English

htaccess重定向到一个URL到另一个URL

[英]Htaccess redirect to one url to another url

I want to redirect url like below 我想重定向网址,如下所示

URL: www.domain.com/en/events/952ls5xs7206 网址:www.domain.com/en/events/952ls5xs7206

Redirect to https://www.domain.com/en/events/952ls5xs7206 重定向到https://www.domain.com/en/events/952ls5xs7206

I tried below code in .htaccess file but not working. 我尝试在.htaccess文件中使用以下代码,但无法正常工作。

RewriteEngine On

RewriteCond %{HTTPS} !on

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

your code from above should work. 您上面的代码应该可以工作。 everything is fine :) 一切顺利 :)

you have to be sure mod_rewrite is activated in your php.ini 您必须确保在您的php.ini 激活mod_rewrite
if your on linux you can activate it with a2enmod rewrite 如果您在Linux上,则可以使用a2enmod rewrite激活它
and then try something like this and put it at top of your .htaccess file 然后尝试这样的操作,并将其放在您的.htaccess文件顶部

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

or with php you can force it like: 或使用php,您可以强制执行以下操作:

// Force HTTPS for security
if($_SERVER["HTTPS"] != "on") {
 $pageURL = "Location: https://";
 if ($_SERVER["SERVER_PORT"] != "80") {
  $pageURL .= $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . $_SERVER["REQUEST_URI"];
 } else {
  $pageURL .= $_SERVER["SERVER_NAME"] . $_SERVER["REQUEST_URI"];
 }
 header($pageURL);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM