Forum Moderators: phranque

Message Too Old, No Replies

301 Redirect - removed trailing / now need to redirect

         

Maximus1000

6:54 pm on Jul 15, 2010 (gmt 0)

10+ Year Member



My site for some reason was adding a trailing / to every single page, include those with .html. So a typical link would be www.example.com/product.html/

My web programmer was able to change the script I was using to not add the trailing /. However Google has everything indexed with the trailing /. I have been trying to figure out the best way to create a 301 redirect within my .htaccess file that would redirect anyone going to any page on my site to the link without the /. what would be the best way to do this?

g1smd

10:01 pm on Jul 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



RewriteRule ^([^.]+)\.html/$ http://www.example.com/$1 [R=301,L]


Now would be a very good time to also rid yourself of the .html extension too.

Maximus1000

11:01 pm on Jul 15, 2010 (gmt 0)

10+ Year Member



thank you so much. how would I make a rule that would address the trailing / issue and also would also redirect people from the .html extension? I have been thinking about doing that, but I am just curious about the redirecting because several of my customers have probably bookmarked my pages.

g1smd

12:10 am on Jul 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Add a question mark:

RewriteRule ^([^.]+)\.html/?$ http://www.example.com/$1 [R=301,L]

Maximus1000

1:46 am on Jul 16, 2010 (gmt 0)

10+ Year Member



awesome, thank you very much that did the trick. It wasnt working at first because I put it in the bottom of my htaccess file, but after moving it to the top it started working.

g1smd

11:44 am on Jul 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Redirects should be listed from most to least specific, with the non-www to www canonical redirect coming last.

If your site uses a mixture of Redirect and RewriteRule change ALL of the rules to use RewriteRule.

If you have both redirects and rewrites, list all of the rewrites after the non-www to www canonical redirect.

Maximus1000

5:51 pm on Jul 16, 2010 (gmt 0)

10+ Year Member



mmm. so do you think that should go on the bottom instead? Whenever I put it on the bottom though it stops redirecting.

here are the contents of my file. Do you think there is anything there that is interfering it when i put it on the bottom? I appreciate all of your help. (example was changed to my site name).


RewriteRule ^([^.]+)\.html/?$ http://www.example.com/$1 [R=301,L]

DirectoryIndex index.php

<IfModule mod_php5.c>

php_value memory_limit 1024M

php_value max_execution_time 18000

php_flag magic_quotes_gpc off

php_flag session.auto_start off

php_flag suhosin.session.cryptua off

php_flag zend.ze1_compatibility_mode Off


</IfModule>


<IfModule mod_security.c>

SecFilterEngine Off

SecFilterScanPOST Off

</IfModule>

<IfModule mod_deflate.c>

</IfModule>


<IfModule mod_ssl.c>

SSLOptions StdEnvVars

</IfModule>



<IfModule mod_rewrite.c>

RewriteEngine on

RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

RewriteCond %{REQUEST_URI} !^/(media|skin|js)/

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-l

RewriteRule .* index.php [L]

</IfModule>


AddDefaultCharset Off


<IfModule mod_expires.c>

ExpiresDefault "access plus 1 year"

</IfModule>

Order allow,deny

Allow from all

g1smd

5:58 pm on Jul 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



It needs to go directly after the
RewriteEngine On
directive.

Maximus1000

7:36 pm on Jul 16, 2010 (gmt 0)

10+ Year Member



awesome, it worked. thank you so much, i appreciate it