I
I
IvanIF2019-10-09 22:26:17
htaccess
IvanIF, 2019-10-09 22:26:17

How to implement a 301 redirect correctly?

There is a site with implemented CNC (I will show on the example of one page).
Here is the NC implementation on one of the pages:

AddDefaultCharset UTF-8
Options +FollowSymLinks
RewriteEngine On

RewriteRule ^news/(sport)$ /pages/news.php?type=sport [L]

i.e. the page is available at example.com/news/sport I
recently started removing duplicate pages using 301 redirects. Here is an example of my redirect from www to non- www :
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

So, the problem is that when I click on the link:
www.example.com/news/sport , in theory I should go to
example.com/news/sport (without www), but in the end I go to
example.com /pages/news.php?type=sport (for some reason there is no cnc here)
All cncs are reset!!! What's the matter? How to fix???

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2019-10-09
@IvanIF

301 redirect set higherRewriteRule ^news/(sport)$ /pages/news.php

RewriteEngine On

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

RewriteRule ^news/(sport)$ /pages/news.php?type=sport [L]

A
artsiom1976, 2019-10-10
@artsiom1976

redirect from www to non-www with https

RewriteEngine on
RewriteCond %{HTTPS}_%{HTTP_HOST} ^(?|off_(?:www\.)?(.*)|on_www\.(.*)) [NC]
RewriteRule .* https://%1/$0 [R=301,L]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question