E
E
Evgeniy Golovin2014-12-20 22:52:32
htaccess
Evgeniy Golovin, 2014-12-20 22:52:32

How to remove duplicates using htaccess?

I'm trying to get rid of using htaccess:
1. index.php
2. remove the slash at the end
3. add www

I do this

Options  -Indexes
RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.site.ru/ [R=301,L]

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

RewriteRule ^.htaccess$ - [F]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index.php


Everything works, but there are a couple of things

I added more lines to redirect errors 403 and 404

ErrorDocument 404 /404
ErrorDocument 403 /403


And it turns out that when I access the folder with pictures, it transfers me to the root folder

www.site.ru/home/admin/data/www/site.ru/images?men...

The next problem is that the line www.site.ru/index .php?menu=page doesn't redirect to /

Tell me what's wrong.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeniy Golovin, 2014-12-20
@JonGol

problem with
Decided like this:

if (!empty($_SERVER['QUERY_STRING']) && empty($_SERVER['REDIRECT_URL'])) {
    header("HTTP/1.1 301 Moved Permanently");
    header("Location: /");
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question