Forum Moderators: phranque

Message Too Old, No Replies

301 mod rewrite

redirect a file url with no extension to one with an extension

         

ibizavenue

11:11 am on Nov 27, 2006 (gmt 0)

10+ Year Member



I made an error with the naming of one of my files. Forgot the extension. So it ended up being simply "browse-oceania" instead of "browse-oceania.php".

And since I didn't notice for a while, it is now indexed without the extension.

I'd like to permanently redirect references of browse-oceania to browse-oceania.php.

Have tried

RewriteRule ^browse-oceania$ http://www.example.com/browse-oceania.php [R=301,L]

and it appears to do nothing.

I did a simple test with

RewriteRule ^browse-oceania\.html$ http://www.example.com/browse-oceania.php [R=301,L]

and this works.

Have gone through numerous posts and the documentation you refer to but can't seem to find any similar examples or references.

Any suggestions?

Thank you for your time, much appreciated.

[edited by: jdMorgan at 1:26 pm (utc) on Nov. 27, 2006]
[edit reason] No URLs, please. See TOS. [/edit]

ibizavenue

1:30 pm on Nov 27, 2006 (gmt 0)

10+ Year Member



Apologies regarding posting the URL in the message. I cut and pasted the text from the .htaccess file without reviewing properly.

jdMorgan

1:35 pm on Nov 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Since your test with a nonexistent URL worked, then

RewriteRule ^browse-oceania$ http://www.example.com/browse-oceania.php [R=301,L]

should have worked as well, unless mod_dir or mod_negotiation is getting involved before mod_rewrite can run.

Try this:


RewriteRule ^browse-oceani[b]a/?$[/b] http://www.example.com/browse-oceania.php [R=301,L]

This will make the rule work even if mod_dir appends a trailing slash to the URL-path, or if it doesn't as well, since the trailing slash in the pattern is marked as optional by the "?" quantifier.

If that doesn't help, then try adding "-MultiViews" to your Options directive if you have one in your .htaccess, or adding the whole line:


Options -MultiViews

above your rewrite code.

I'm assuming that browse-oceania.php resides in the root directory of the site. If not, further adjustments may be needed.

Jim

ibizavenue

2:17 pm on Nov 27, 2006 (gmt 0)

10+ Year Member



Thanks Jim.

The
Options -Multiviews

did the job.

Changing it to
RewriteRule ^browse-oceania/?$ http://www.example.com/browse-oceania.php [R=301,L]

was not sufficient.

Any side effects, with setting this option? I did a search, to try to understand exactly what this does but I didn't find a whole lot of info.

I think it's Ok but just want to make sure.

And do you think I should have had to set this? Is this specific to how my ISP has the Apache server configured?

Thanks again for your help.

jdMorgan

3:02 pm on Nov 27, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The simple way of looking at multiviews is that it tries to find a 'best match' for the requested URL-path if that exact path does not exist. It does so based on the partial URL-path and client/browser language and content-type settings.

A surprising number of hosts enable content negotiation by default, despite the fact that it can make a mess of your site's search results due to the potential for duplicate content problems (same content appears for multiple URLs). While duplicate content is not "penalized" per se (in my opinion), it does cause the search engines to pick one URL out of all same-content URLs, and eliminate the rest from their search results. Unfortunately, the URL they pick is often not the one that your prefer.

If you don't know that you use multiviews/content negotiation, then it's very doubtful that you need it.

Jim