There are .htaccess as follows:

DirectoryIndex index.php Options FollowSymLinks RewriteEngine On RewriteRule ^(.*/)?\.svn/ - [F,L] RewriteCond %{HTTP_HOST} ^mySite\.com$ [OR] RewriteCond %{HTTP_HOST} ^myCite\.com$ RewriteRule ^(.*)$ http://www.mySite.com/$1 [R=301,L] RewriteCond %{HTTP_HOST} www.(.*?).mySite\.com$ RewriteRule ^(.*)$ http://%1.mySite.com/$1 [R=301,L,NC,QSA] RewriteCond %{REQUEST_FILENAME} !-s RewriteRule !(.*).(txt|css|jpg|gif|png|ico|js|htc)$ /index.php [L] Header set Cache-Control "max-age=29030400, public" ErrorDocument 404 http://www.mySite.com/404.html 

Task:

      1. Remove all repeated slashes;
      2. 301 redirect from pages without a slash to a slash.
those. Addresses: www.mySite.com//category/ , www.mySite.com//category , www.mySite.com/category 301 redirect to www.mySite.com/category/

But, there is one BUT - we do not process AJAX requests.

I tried the following lines, inserted between 4 and 6 lines:

 # Check whether the repeated slashes (//) more than two times. RewriteCond %{THE_REQUEST} // RewriteRule .* /$0 [R=301,L] # Add trailing slash RewriteCond %{HTTP:X-Requested-With} !=XMLHttpRequest RewriteCond %{REQUEST_URI} !(/$|\.) RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 

But, there are a lot of redirections and with a large attendance the server "falls".

How can you handle this with one rule or is it better to do it in PHP code?

PS: offer a solution to the problem, not questions: "How did it happen?"

  • Where do you get double (and more) slashes in the addresses? - Visman
  • We need a solution to the problem, and not leading questions. There is an SEO requirement and they need to be implemented. For example, they can be taken if the user manually entered the URL. Of course, it is logical to show a 404 error. But, if you have a large online store, then it is more profitable for you to “cut off” an extra slash and redirect to the product page, since You risk losing the user. - ilya

0