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):
you shouldn't have to redirect it, your browser will do it automatically by urlencoding the spaces with %20. That's why if you enter (hold your mouse over this to see the link!) http://www.mysite.info/My Stupid Page With Spaces.htm in your browser, your browser will then auto-change it to http://www.mysite.info/My Stupid Page With Spaces.htm and request it.
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.
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.
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.
redirect all calls to a pagesorter.php and you can strip spaces using some preg call and then map the right page.
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)
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.
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.
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.
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?
I mean it doesn't redirect: http://www.marsplanet.co.uk/life on mars.htm RewriteRule "^life on mars.htm$" /lifeonmars.htm [L] Code (markup):
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?
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.
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.