htaccess - Setup Permanent 301 Redirects after moving to Https

admin2025-06-05  0

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

i moved my site from http to https now i want to redirect the user into the new url but evry time i'm trying to edit .htaccess file i'm getting an error

this is the working file content where xxxz is site name

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

# END WordPress
RewriteCond %{HTTP_HOST} ^xxxz\.qa$ [OR]
RewriteCond %{HTTP_HOST} ^www\.xxxz\.qa$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]    {32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "http\:\/\/xxxz\\.qa" [R=301,L]

what i'm trying to edit is to add the following code in the top of the file as i read

RewriteEngine on
RewriteCond %{HTTP_HOST} ^xxxz.qa [NC,OR]
RewriteCond %{HTTP_HOST} ^www.xxxz.qa [NC]
RewriteRule ^(.*)$ /$1 [L,R=301,NC]

but its not working so what do u think

Closed. This question is off-topic. It is not currently accepting answers.

Your question should be specific to WordPress. Generic PHP/JS/SQL/HTML/CSS questions might be better asked at Stack Overflow or another appropriate Stack Exchange network site. Third-party plugins and themes are off-topic for this site; they are better asked about at their developers' support routes.

Closed 6 years ago.

Improve this question

i moved my site from http to https now i want to redirect the user into the new url but evry time i'm trying to edit .htaccess file i'm getting an error

this is the working file content where xxxz is site name

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

# END WordPress
RewriteCond %{HTTP_HOST} ^xxxz\.qa$ [OR]
RewriteCond %{HTTP_HOST} ^www\.xxxz\.qa$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]    {32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "http\:\/\/xxxz\\.qa" [R=301,L]

what i'm trying to edit is to add the following code in the top of the file as i read

RewriteEngine on
RewriteCond %{HTTP_HOST} ^xxxz.qa [NC,OR]
RewriteCond %{HTTP_HOST} ^www.xxxz.qa [NC]
RewriteRule ^(.*)$ https://www.xxxz.qa/$1 [L,R=301,NC]

but its not working so what do u think

Share Improve this question asked Jan 1, 2019 at 7:27 Abdullaziz HappyAbdullaziz Happy 212 bronze badges 1
  • Welcome to WPSE, I assume you have taken a look on the numerous answers as given here?! – Charles Commented Jan 1, 2019 at 10:02
Add a comment  | 

2 Answers 2

Reset to default 1
RewriteCond %{HTTP_HOST} ^xxxz.qa [NC,OR]
RewriteCond %{HTTP_HOST} ^www.xxxz.qa [NC]
RewriteRule ^(.*)$ https://www.xxxz.qa/$1 [L,R=301,NC]

This will result in a redirect loop as it will repeatedly redirect https://www.xxxz.qa/<url> to https://www.xxxz.qa/<url> again and again...

If you want to redirect from HTTP then you need to check that the request was for HTTP before redirecting to HTTPS. For example:

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [R=301,L]

No need for the NC flag, as you are simply matching everything anyway.


However, this conflicts with the existing directives at the end of your file:

RewriteCond %{HTTP_HOST} ^xxxz\.qa$ [OR]
RewriteCond %{HTTP_HOST} ^www\.xxxz\.qa$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]    {32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "http\:\/\/xxxz\\.qa" [R=301,L]

These directives should probably be deleted. (Fortunately, they probably aren't doing anything anyway - because they are after the WordPress front-controller.)

The best way for setting up Permanent 301 Redirects is by editing .htaccess with the required redirection code. Follow these steps:

  1. Open your cPanel account.
  2. Click on File Manager under Files section.
  3. Click on public_html directory in the left sidebar.
  4. Search for the .htaccess file. Right-click on it. Click on Edit.
  5. A pop up box will appear. Click on Edit.
  6. A new tab will be opened. Here, you have to add the redirect code. For example, your old page is https://yoursite/old-page.htm, and the new page is https://yoursite/new-page.htm. In this case, the redirect code will be:

    Redirect 301 /old-page.htm/ /new-page.htm
    

You can find more information about these steps right here.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749054011a315962.html

最新回复(0)