Forum Moderators: phranque

Message Too Old, No Replies

Mod Rewrite Help Please - 301 and Trailing Slash Problems!

         

Lord_Elpus

5:08 pm on Jan 27, 2011 (gmt 0)

10+ Year Member



Hello

Is anyone able to help me, please, with a 301 redirect query?

I have moved a site from WP to HTML.

With WP the pages had no extension but now they have .htm extensions and I need to be able to redirect the URL's of each page.

I have found various code for that using the .htaccess file and I have it working to redirect greenwidgets.co.uk/used to greenwidgets.co.uk/used.htm.

The problem is that the search engine indexing of my WP sites includes an extra / for each page, ie greenwidgets.co.uk/used/ and I cannot get that url to redirect to greenwidgets.co.uk/used.htm.

The code that I am currently using in my .htaccess is:-

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !\..+$
RewriteRule ^(.*)$ /$1.html [R=301,L]

It's the extra / that is causing me havoc!

Does anyone have ideas, please?

Thank you.

Peter

Lord_Elpus

2:26 pm on Jan 28, 2011 (gmt 0)

10+ Year Member



Can anyone help me, please?

I really need (I think) the code to redirect

greenwidgets.co.uk/used/

to

greenwidgets.co.uk/used.htm

or perhaps to take greenwidgets.co.uk/used....add the trailing slash...and then redirect to greenwidgets.co.uk/used.htm

Anyone know how I can do that, please?

Thank you!

Peter

jdMorgan

10:09 pm on Jan 31, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteCond $1 !\.[^./]+$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+(/[^/])*)/?$ http://www.example.com/$1.html [R=301,L]

Jim

Lord_Elpus

9:59 am on Feb 1, 2011 (gmt 0)

10+ Year Member



Brilliant, thank you!

Works perfectly and, needless to say, I would never have worked that out for myself!

I really am grateful for your help, Jim.

Best regards,

Peter