View Full Version : URL Rewriting...htaccess?
landing
07-27-06, 11:52 AM
Hi,
Some pages on one of my websites have lengthy URLs.
mydomain.com/resources/index.php?page=begginers
I would like to allow users to visit mydomain.com/beginners, and have this redirected to the above URL.
I've seen this done on sites before but I'm unsure how. I think it's a htaccess thing. Could someone show me an example of how to acheive this? I want to have many 'shortcut' URL's.
Thanks in advance
You can do this with mod_rewrite, which you can turn on in a .htaccess file (if your provider allows this).
For example, I have a page called http://www.swissbytes.de/tiki/tiki-index.php?page=HormonesAndWater, but I want the user to access it like
http://www.swissbytes.de/hormone or
http://www.swissbytes.de/hormones
This is what I do:
# Turn the engine on
RewriteEngine on
# Rewrite
RewriteRule ^hormones?/?$ http://www.swissbytes.de/tiki/tiki-index.php?page=HormonesAndWater [R]
You see that a RewriteRule consists of 2 parts: the pattern (which tells apache if the rule applies) and the action.
Here the pattern sais:
if the url starts (^) with "hormone" potentially followed by "s" (because of the ?), potentially followed by "/" (another ?) and then ends ($), fire this rule.
The Rule then sais which page to redirect to, [R] sends a 302 Code back to the browser, so it knows that the page has moved.
Have Fun!
landing
07-27-06, 04:13 PM
Superb. Thanks duesi.
I'm getting a server configuration error after uploading a .htaccess file, and I can't actually see the htaccess file in my FTP. Is this an indication my server doesn't allow them?
For the first Problem, get a decent FTP program like
http://filezilla.sourceforge.net/ and make sure to "show hidden files", because the leading dot of .htaccess means its a hidden file.
Its possible that your provider does not support it, but an error on your side is also an option.
Put just
RewriteEngine on
in the file, if this does work, your provider shoudl support it.
Cheers!
landing
07-28-06, 10:05 AM
Thanks again. I've been informed that my server does support it, so it may be an error my end.
I'll give it another go later on and let you know.
vBulletin® v3.6.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.