Current location: Hot Scripts Forums » Other Discussions » Web Servers » URL Rewriting...htaccess?


URL Rewriting...htaccess?

Reply
  #1 (permalink)  
Old 07-27-06, 10:52 AM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
URL Rewriting...htaccess?

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
__________________
Always sanitise your data


Best regards
Reply With Quote
  #2 (permalink)  
Old 07-27-06, 02:30 PM
duesi's Avatar
duesi duesi is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 225
Thanks: 0
Thanked 0 Times in 0 Posts
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-i...rmonesAndWater, 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:

Code:
# 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!
__________________
Duesi

"One of the great skills in using any language is knowing what not to use, what not to say" (Ron Jeffries)

http://www.swissbytes.de
Reply With Quote
  #3 (permalink)  
Old 07-27-06, 03:13 PM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
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?
__________________
Always sanitise your data


Best regards
Reply With Quote
  #4 (permalink)  
Old 07-28-06, 12:46 AM
duesi's Avatar
duesi duesi is offline
Wannabe Coder
 
Join Date: Jun 2006
Posts: 225
Thanks: 0
Thanked 0 Times in 0 Posts
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

Code:
RewriteEngine on
in the file, if this does work, your provider shoudl support it.

Cheers!
__________________
Duesi

"One of the great skills in using any language is knowing what not to use, what not to say" (Ron Jeffries)

http://www.swissbytes.de
Reply With Quote
  #5 (permalink)  
Old 07-28-06, 09:05 AM
landing's Avatar
landing landing is offline
Coding Addict
 
Join Date: Jul 2006
Location: Scotland
Posts: 302
Thanks: 0
Thanked 0 Times in 0 Posts
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.
__________________
Always sanitise your data


Best regards
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
can someone help with htaccess and php problem tigherrdk PHP 6 03-09-09 02:28 AM
htaccess ? arale Script Requests 1 05-10-06 07:46 PM
The Reasons Why do you Need URL Rewriting MODULE to Enchance your Web? handry PHP 11 08-05-05 07:32 AM
Search Engine URL: htaccess, dynamic php, & Frontpage ext. cebuy PHP 5 11-12-03 11:45 PM
htaccess client area mdittrich Script Requests 2 10-01-03 01:57 PM


All times are GMT -5. The time now is 01:25 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.