Forum Moderators: phranque

Message Too Old, No Replies

Error redirecting My Page.htm to my_page.php

         

buguela

1:38 pm on Nov 25, 2005 (gmt 0)

10+ Year Member



I'm trying to redirect my page called My Page.htm to an address [mysite.com...]

How can i do that if i have a space between the word "My" and "Page"?

I've tried doing this:

RewriteRule ^My Page.htm$ [mysite.com...]

But didn't work.

So i've tryed this too:

RewriteRule ^My%20Page.htm$ [mysite.com...]

And nothing happens... anyone can help me?

Jackson Hole

2:08 pm on Nov 25, 2005 (gmt 0)

10+ Year Member



Your post made me curious, so I did some testing on my server. I don't know squat about rewriting, so if you really want to go that route, this won't help you.

But I was able to 301 redirect a file with a space in the filename by putting quotes around the filename. I'm by no means an apache expert, so be sure to test thoroughly as your results might differ on a different server. But try dropping this into your .htaccess file:

redirect 301 "/my page.htm" http://www.example.com/page.htm

Alternatively, I'm not sure exactly what your goals are for this redirect, but you could just put this between the <head> tags in "my page.htm":

<meta http-equiv="refresh" content="5;url=http://www.mysite.com/my_page.php">

jdMorgan

6:48 pm on Nov 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'd suggest:

RewriteRule ^My\ Page\.htm$ http://www.mysite.com/my_page.php [R=301,L]

escaping the space and literal period with backslashes, and adding the required space before the flags.

Jim

Jackson Hole

7:30 pm on Nov 25, 2005 (gmt 0)

10+ Year Member



jdMorgan, you've piqued my curiousity. What's the difference between the following and what you suggested?

redirect 301 "/my page.htm" [mysite.com...]

I've read some articles and some threads here about rewriting, but I haven't played around with it enough to really know it.

jdMorgan

10:36 pm on Nov 25, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I haven't played with quoted patterns much, so the only difference I can be sure of is that your pattern is not anchored, and so would match any local URL-path tht contained your string in any position.

Jim

Jackson Hole

6:21 pm on Nov 26, 2005 (gmt 0)

10+ Year Member



I was under the impression that the "redirect 301..." was just a simple redirect of a single page, with no regex / pattern matching at all. Am I wrong?

jdMorgan

7:23 pm on Nov 26, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The Redirect [httpd.apache.org] directive makes use of prefix matching; Any URL which matches the given URL-path prefix will be redirected to the given new URL, with any unmatched URL-path information appended.

Thus, for example:


Redirect 301 /widgets_ http://www.example.com/products/widgets-

will redirect /widgets_blue to /products/widgets-blue, adding the "products" subdirectory and changing the underscore to a hyphen.

If an exact one-to-one redirect is desired, then a full URL-path should be specified, or RedirectMatch can be used instead.

I offered a RewriteRule solution on the basis of the original post asking about a RewriteRule; Either will work. The use of mod_rewrite or mod_alias for simple rewrites like this is largely a matter of personal preference.

Jim