hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Friendly urls
Reply

Forum Jump

Friendly urls

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 01-19-2006, 04:32 AM
stuffradio stuffradio is offline
Web Hosting Guru
 
Join Date: Dec 2005
Posts: 326

Friendly urls


Hi,

I want to know how to use these. The simplest way to use them. Example I want to be able to convert:

myblog.com/blog.php?u=username to
myblog.com/username

Please help,

Thanks



Sponsored Links
  #2  
Old 01-19-2006, 05:55 AM
Burhan Burhan is offline
Community Guide
 
Join Date: Jul 2003
Location: Kuwait
Posts: 5,099
Google for 'mod_rewrite tutorials'. For your specific case:

RewriteRule ^myblog.com/(.*?)$ myblog.com/blog.php?u=$1

__________________
In order to understand recursion, one must first understand recursion.
If you feel like it, you can read my blog
Signal > Noise

  #3  
Old 01-21-2006, 03:18 AM
extras extras is offline
Web Hosting Master
 
Join Date: Aug 2005
Location: Canada
Posts: 838
Quote:
RewriteRule ^myblog.com/(.*?)$ myblog.com/blog.php?u=$1
This may go into infinite looping (when used in .htaccess).

If the username never contains any period, you can use it to stop looping.
RewriteRule ^myblog.com/([^.]*)$ myblog.com/blog.php?u=$1

If you need to allow any char in the user name:
RewriteCond %{REQUEST_URI} !^/+myblog.com/blog\.php
RewriteRule ^myblog.com/(.*)$ myblog.com/blog.php?u=$1

Sponsored Links
  #4  
Old 01-21-2006, 03:40 AM
stuffradio stuffradio is offline
Web Hosting Guru
 
Join Date: Dec 2005
Posts: 326
know where I can get a tutorial on this?

  #5  
Old 01-21-2006, 04:35 AM
flann flann is offline
Newbie
 
Join Date: Jan 2006
Posts: 22

__________________
Flann
Debt Free


  #6  
Old 01-21-2006, 06:43 AM
Burhan Burhan is offline
Community Guide
 
Join Date: Jul 2003
Location: Kuwait
Posts: 5,099
Quote:
Originally Posted by stuffradio
know where I can get a tutorial on this?
Try the URL Rewriting Guide from the fine folks at Apache (also available with your local Apache install if you have the documentation installed).

__________________
In order to understand recursion, one must first understand recursion.
If you feel like it, you can read my blog
Signal > Noise

  #7  
Old 01-21-2006, 12:01 PM
extras extras is offline
Web Hosting Master
 
Join Date: Aug 2005
Location: Canada
Posts: 838
I think it's much better to do URL parsing in the script, just like some CMS do.

Badly written long long list of RewriteRules so common to "Short URL/SEO friendly URL" hype
is a goof way to waste server resource and complicate your life, IMHO.


Since you are using PHP anyway, why not to use it's facility?
It's much much easier to do it in PHP (for many people) and it doesn't tax the requests for non-php files.

Example:

This goes in myblog.com/.htaccess (or Virtual host section with <directory ... >)
Code:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /myblog.com/
RewriteRule !^index.php  index.php [L]
And in the myblog.com/index.php, you check $_SERVER['REDIRECT_URL'] or
other env variables to get the URL, and parse it if needed.

You should be able to find lots of examples in OpenSource CMS/Blog code, too.

Reply

Related posts from TheWhir.com
Title Type Date Posted


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?