Forum Moderators: phranque

Message Too Old, No Replies

RedirectMatch 301 help

using regular expressions

         

parkside

10:06 pm on Jan 17, 2010 (gmt 0)

10+ Year Member



I'm trying to do a redirect like the following

www.mysite.com/thiscat/thispost

to

www.mysite.com/thiscat/thispost.html

The closest I've come to is

 RedirectMatch 301 /thiscat/([a-zA-Z0-9]+/.html) /thiscat/$1.html 

(I know this code doesn't currently work) I'm not quite sure how to exclude pages that have already been redirected.

Any help would be greatly appreciated.

Cheers,

phranque

8:07 am on Jan 18, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



you are probably better off using mod_rewrite instead of mod_alias for that application as RewriteCond would be helpful here.

g1smd

6:57 pm on Jan 18, 2010 (gmt 0)

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



The example code doesn't match the question (as the example code redirects to exactly itself - actually it has a typo: 'page.html' will redirect to 'page.html.html'), and I'm not sure if in fact you should be asking for a rewrite rather than a redirect.

To be sure, a redirect ends the current HTTP transaction and the browser makes a new request for the new URL. Why you would be redirecting a short URL to a longer URL is unclear to me. That's why I suspect you might want a rewrite; when the browser asks for /page, the server fetches the 'page.html' file from the server.

Please clarify exactly the requirements, especially concerning whether a redirect or rewrite is required.

parkside

7:59 pm on Jan 18, 2010 (gmt 0)

10+ Year Member



Maybe it would be best to ignore my attempt. I have an old site with the structure of www.mysite.com/thiscat/thispost and a new site the structure www.mysite.com/thiscat/thispost.html

I'm trying to preserve any external links - google, etc.

The reason behind having '.html' at the end of the new site is because Wordpress seems to have a fit when using the permalink structure '/thiscat/thispost', unless i have something like 'html' on the end

Thanks for your help

jdMorgan

8:45 pm on Jan 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Does www.examplecom/thiscat/thispost.html actually exist as a physical file, or is it a URL to be handled by WordPress?

And not to de-rail the current discussion, but don't forget to check out this thread [webmasterworld.com] on speeding up your WP rewrite code (after the current problem is dealt with).

Jim

parkside

8:54 pm on Jan 18, 2010 (gmt 0)

10+ Year Member



It is a URL handled by Wordpress. Ultimately, the best outcome would be to not using '.html' at all.

This problem cropped up when I changed the default permalink structure to 'category/postname'
Wordpress would give a URL such as 'www.mysite.com/category/news/newsitem'
I managed to get rid of 'category' from the url but this forced me to add '.html' or else suffer an internal server error

parkside

9:40 pm on Jan 18, 2010 (gmt 0)

10+ Year Member



After a bit of thought I decided that I was going about this the wrong way. I have found a plugin that actually works, removing '/category' without the need for '.html' at the end of the permalink.

This tidies up Wordpress permalinks quite nicely. here is a link: [wordpress.org...]

Thank you so much, I am flash designer by profession so all apologies if i sound out of my depth.

Cheers,

phranque

10:50 am on Jan 19, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



sorry - i should have asked some questions rather than tossing out a suggestion.
in any case:
welcome to WebmasterWorld [webmasterworld.com], parkside!