1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

.htaccess redirect url with spaces

Discussion in 'Apache' started by Astroman, Aug 21, 2009.

  1. #1
    I've tried all sort with this but can't figure it out.

    How do you redirect this

    My Stupid Page With Spaces.htm
    Code (markup):
    to this:

    http://www.mysite.info/mypagewithoutspaces.htm
    Code (markup):
    I thought this might do it but it doesn't:

    RedirectMatch permanent "^My Stupid Page With Spaces.htm$" http://www.mysite.info/mypagewithoutspaces.htm
    Code (markup):
     
    Astroman, Aug 21, 2009 IP
  2. Bohra

    Bohra Prominent Member

    Messages:
    12,573
    Likes Received:
    537
    Best Answers:
    0
    Trophy Points:
    310
    #2
    My%20Stupid%20Page%20With%20Spaces.htm use that instead of My Stupid Page With Spaces.htm
     
    Bohra, Aug 21, 2009 IP
  3. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #3
    szalinski, Aug 21, 2009 IP
  4. Astroman

    Astroman Well-Known Member

    Messages:
    2,355
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    135
    #4
    That doesn't work, I already tried it.

    @szalinski, I don't have to redirect it, I want to redirect it. I bought a site off someone and he named some of the html pages with spaces in, like My Stupid Page With Spaces.htm - I hate them like that and want to rename the file so I need to redirect them to avoid 404s.
     
    Astroman, Aug 21, 2009 IP
  5. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Ok, let's take this step by step then. Why, exactly, are you receiving a 404 error? - is it because you've already made a htaccess file and it's incorrect in some way? as i don't see why you'd get a 404 trying to access any file with spaces in its name, as long as you access it directly.

    and can you perhaps show what you've already been trying? thanks.
     
    szalinski, Aug 21, 2009 IP
  6. Astroman

    Astroman Well-Known Member

    Messages:
    2,355
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    135
    #6
    I'm not receiving a 404 error, but I would be creating them for people via google if I changed the file names which is what I am going to do.
     
    Astroman, Aug 21, 2009 IP
  7. pepprs

    pepprs Peon

    Messages:
    195
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    0
    #7
    redirect all calls to a pagesorter.php and you can strip spaces using some preg call and then map the right page.
     
    pepprs, Aug 21, 2009 IP
  8. campolar

    campolar Peon

    Messages:
    2,683
    Likes Received:
    244
    Best Answers:
    0
    Trophy Points:
    0
    #8
    First i'd ask how did you get a page name with spaces? You gotta include the %20 else it wont work (as far as i know)
     
    campolar, Aug 21, 2009 IP
  9. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #9
    if you change the filenames manually, then hey presto, no more spaces. other than that i really can't understand what on earth you don't like spaces for - unless it's some sort of seo thing.
     
    szalinski, Aug 21, 2009 IP
  10. Astroman

    Astroman Well-Known Member

    Messages:
    2,355
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    135
    #10
    Okay, this forum fills in the spaces with %20 as you might expect, however you don't need them to see:
    http://www.marsplanet.co.uk/A page with space in the url.htm apart from in Internet Explorer.

    Anyways, can anyone who hasn't a clue about .htaccess please stop replying, I don't mean you campolar, as it's not helping at all.

    Examples;

    This works:

    RedirectMatch permanent ^/has-therebeenlife-on-mars.htm$ http://www.marsplanet.co.uk/lifeonmars.htm
    Code (markup):
    This does not:

    RedirectMatch permanent ^/A%20page%20with%20space%20in%20the%20url.htm$ http://www.marsplanet.co.uk/lifeonmars.htm
    Code (markup):
    I'm not looking for a 'just do something else' solution, I really want to know how to do this in .htaccess/apache because it's bugging me.
     
    Last edited: Aug 21, 2009
    Astroman, Aug 21, 2009 IP
  11. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #11
    for the last time, YOUR BROWSER 'fills them in'

    hmm, real subtle.

    this example is suggesting that if somebody types "/has-therebeenlife-on-mars.htm" in their browser, they'll be redirected to "/lifeonmars.htm" (actually, you should be using just the "/lifeonmars.htm" part if it's all on the same domain). this hasn't anything to do with spaces, so more confusion.

    from this example, i have now gathered that the file itself doesn't have spaces in it at all (waheyy). you are trying to redirect people who (for whatever weird reason) try to access a file with spaces in between the words, to the actual file 'minus the spaces'. hmm. the only conclusion i can draw from this is: if the links on your site are linking to the files with spaces (perhaps what it used to be), but the files themselves don't have spaces, then it's much easier to change just the html/php links. but seeing as you like to do things with a htaccess, let's continue.

    So - surely you have tried this:
    RewriteEngine On
    RewriteRule "^life on mars.htm$" /lifeonmars.htm [L]
    Code (markup):
    This last example means that if someone tries to access /life on mars.htm (which will get auto urlencoded by their browser to /life%20on%20mars.htm), they'll be sent to the actual file which is /lifeonmars.htm. course, that lifeonmars.html will be loaded, but the url in their addressbar will stay the same (with space).

    Now I really hope I haven't gone and misunderstood you completely.
     
    szalinski, Aug 21, 2009 IP
  12. Astroman

    Astroman Well-Known Member

    Messages:
    2,355
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    135
    #12
    Yes, I have tried that, it doesn't work...
     
    Astroman, Aug 21, 2009 IP
  13. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Then you're typing it incorrectly, as it works for me. Assuming my version of working is the same as what you're expecting. I put a file under my root domain, called lifeonmars.htm. then i type in my browser
    http://mydomain.com/life on mars.htm
    Code (markup):
    and the browser addresssbar shows
    http://mydomain.com/life%20on%20mars.htm
    Code (markup):
    and the lifeonmars.htm is loaded fine, as i see the text i put in it earlier.

    So try again, and note the quotes I put around "^life on mars.htm$" so it can understand the spaces there.

    And when you say it doesn't work, are you receiving a 500 internal server error, or is it just not the way you wanted this to work?
     
    Last edited: Aug 21, 2009
    szalinski, Aug 21, 2009 IP
  14. Astroman

    Astroman Well-Known Member

    Messages:
    2,355
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    135
    #14
    Astroman, Aug 21, 2009 IP
  15. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #15
    But it does; it doesn't matter whether you directly input 'life on mars.htm' or life%20on%20mars.htm into your browser's addressbar, it will always be encoded to life%20on%20mars.htm anyway. and it does work, i've tried it a thousand times just to be sure. what's happening when you try it - a 500 error, or what?
     
    szalinski, Aug 21, 2009 IP
  16. Astroman

    Astroman Well-Known Member

    Messages:
    2,355
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    135
    #16
    I gave you the link to show you what is happening, it doesn't work.
     
    Astroman, Aug 22, 2009 IP
  17. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #17
    the link is no use really, show me the htaccess code you used.
     
    szalinski, Aug 22, 2009 IP
  18. Astroman

    Astroman Well-Known Member

    Messages:
    2,355
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    135
    #18
    RewriteRule "^life on mars.htm$" /lifeonmars.htm [L]
     
    Astroman, Aug 22, 2009 IP
  19. szalinski

    szalinski Peon

    Messages:
    341
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #19
    Did you use RewriteEngine On also? It should be working if you did; if it didn't, i've nothing else to suggest other than your htaccess is probably corrupt, or maybe it isn't having any effect somehow due to a server configuration.
     
    szalinski, Aug 22, 2009 IP
  20. Astroman

    Astroman Well-Known Member

    Messages:
    2,355
    Likes Received:
    71
    Best Answers:
    0
    Trophy Points:
    135
    #20
    Of course it's on. Like I said above, this works:

    RedirectMatch permanent ^/has-therebeenlife-on-mars.htm$ http://www.marsplanet.co.uk/lifeonmars.htm

    or this if you prefer:

    RedirectMatch permanent ^/has-therebeenlife-on-mars.htm$ /lifeonmars.htm

    But it doesn't work with spaces. I guess I'll just give up.
     
    Astroman, Aug 22, 2009 IP