A
A
Alexander2014-07-26 13:50:24
htaccess
Alexander, 2014-07-26 13:50:24

How to make a correct redirect in .htaccess?

Hello!
The site needed a 301 redirect.
At the root of the site is .htaccess with the following content:
.htaccess

<FilesMatch "\.md5$">
    Deny from all
</FilesMatch>
DirectoryIndex index.php
Options -Indexes
# Comment the following line, if option Multiviews not allowed here
Options -MultiViews
AddDefaultCharset utf-8
<ifModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_URI} !\.(js|css|jpg|jpeg|gif|png)$
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php [L,QSA]
</ifModule>
<ifModule mod_headers.c>
    <FilesMatch "\.(jpg|jpeg|png|gif|js|css)$">
  Header set Cache-Control "max-age=3153600, public"
    </FilesMatch>
</ifModule>
Redirect 301 /category/zhenskaya-parfumeria/ http://site.ru/zhenskaya-parfumeria/

When following a link:
site.ru/category/zhenskaya-parfumeria/
issues
site.ru/zhenskaya-parfumeria/
which is what you need, but if the link contains UTM tags of the form:
& utm_source=yandex&utm_medium=cpc&utm_campaign=parfum/
the server gives a 404 error.
However, labels starting with
?utm
are working correctly.
Tell me how to make a correct redirect so that &utm tags work? Will replacing the " & " character with " ? " in htaccess help and how to do it?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
vdem, 2014-07-26
@vdem

I'm actually not an expert in .htaccess, try
Redirect 301 /category/zhenskaya-parfumeria(.*) site.ru/zhenskaya-parfumeria/?$1

N
Nikolai Pinevich, 2016-02-12
@Afres

You can do it like this:

RewriteEngine On
Options +FollowSymLinks
RewriteRule ^category/zhenskaya-parfumeria$     /zhenskaya-parfumeria$1 [QSA,NC,R=301,L]

Here is a good article that describes the flags and all the commands for redirects.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question