Jump to content

  • You cannot start a new topic
  • You cannot reply to this topic

.htaccess 301 Redirect non slash domains and slash domain to .html Rate Topic   - - - - -

 
  • pjlee
  • Newbie
  • Members
  • Join Date: 20-Jan 12
  • 11 posts

Posted 03 May 2013 - 09:45 AM #1

I am trying to add some code to my .htaccess to redirect all slash and non slash urls ( apart from my homepage ) to the .html url.

For example
www.mydomain.com/cat/
www.mydomain.com/cat

should redirect to

www.mydomain.com/cat.html

I have managed to add the following to my .htaccess which redirects www.mydomain.com/cat to the right place www.mydomain.com/cat.html but need some help on how to make slash version redirect to the .html page

RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ [url="http://mydomain.com/$1.html"]http://mydomain.com/$1.html[/url] [R=301,L]


My whole .htaccess looks like this, if anyone has any suggestions on how it should look in light of the above it would be greatly appreciated.

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xxx.xxx.xxx.xx [nc,or]
RewriteCond %{HTTP_HOST} ^mydomain.com [NC]
RewriteRule ^(.*)$ [url="http://www.mydomain.com/$1"]http://www.mydomain.com/$1[/url] [L,R=301]

RewriteCond %{THE_REQUEST} ^.*/index.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]


RewriteCond %{REQUEST_URI} !\.[^./]+$
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ [url="http://mydomain.com/$1.html"]http://mydomain.com/$1.html[/url] [R=301,L]


DirectoryIndex index.html index.php

<IfModule mod_rewrite.c>
RewriteEngine on
# Pleas note that RewriteBase setting is obsolete use it only in case you experience  some problems with SEO addon.
# Some hostings require RewriteBase to be uncommented
# Example:
# Your store url is [url="http://www.yourcompany.com/store/cart"]http://www.yourcompany.com/store/cart[/url]
# So "RewriteBase" should be:
# RewriteBase /store/cart
# RewriteBase /
RewriteCond %{REQUEST_FILENAME} !\.(png|gif|ico|swf|jpe?g|js|css)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php?sef_rewrite=1 [L,QSA]

</IfModule>

Many thanks in advance.