Answer the question
In order to leave comments, you need to log in
How to correctly set up a redirect to an address without a slash?
It is necessary that a redirect be carried out from an address of the form site.ru/ to site.ru
Please tell me how to register correctly
Options -Indexes
ErrorDocument 404 /404.php
<IfModule mod_php5.c>
php_flag session.use_trans_sid off
#php_value display_errors 1
#php_value mbstring.internal_encoding UTF-8
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !/bitrix/urlrewrite.php$
RewriteRule ^(.*)$ /bitrix/urlrewrite.php [L]
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>
<IfModule mod_dir.c>
DirectoryIndex index.php index.html
</IfModule>
<IfModule mod_expires.c>
ExpiresActive on
ExpiresByType image/jpeg "access plus 3 day"
ExpiresByType image/gif "access plus 3 day"
ExpiresByType image/png "access plus 3 day"
ExpiresByType text/css "access plus 3 day"
ExpiresByType application/javascript "access plus 3 day"
</IfModule>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.site\.ru$ [NC]
RewriteRule ^(.*)$ http://site.ru/$1 [R=301,L]
RewriteCond %{REQUEST_URI} ^(.*)/index\.php$
RewriteRule ^(.*)index\.php$ http://%{HTTP_HOST}/$1 [R=301,L]
Answer the question
In order to leave comments, you need to log in
The problem is more complicated than it seems, because in these redirects, for good, you still need to track the status of the recipient, because if there is 404, then there is no point in changing it to 301 + 404, and from the point of view of SEO, this is not feng shui.
Removes multiple slashes in the url if they occur like //
RewriteCond %{REQUEST_URI} !\..+$
RewriteCond %{REQUEST_URI} .*\/\/$
RewriteRule (.*)(\/\/)(.*)$ $1/$3$
RewriteCond %{REQUEST_FILENAME} !^.+\.(jpg|jpeg|gif|png|ico|css|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|ppt|txt|tar|mid|midi|wav|bmp|rtf|js|swf|flv|mp3)$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*[^/])$ $1/ [L,R=301]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question