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
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
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
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
Web Hosting Guru
 
Join Date: Dec 2005
Posts: 326
know where I can get a tutorial on this?

  #5  
Old
Newbie
 
Join Date: Jan 2006
Posts: 22

__________________
Flann
Debt Free


  #6  
Old
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
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
Making Google AdWords Custom Affinity Audiences Work For Web Hosts Blog 2014-10-22 10:35:51
PTisp Listing 2014-10-22 09:48:53
WHIR Networking Event Chicago; always fun and friendly Blog 2013-03-15 13:27:39
Phishing Attack Trends by Country Represented in Netcraft Map Web Hosting News 2012-12-13 15:13:37
GlobalSign Launches Free SSL Configuration Checker to Improve Site Performance, Security Web Hosting News 2012-11-15 11:09:45


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?
WHT Host Brief Email:

We respect your privacy. We will never sell, rent, or give away your address to any outside party, ever.

Advertisement:
Web Hosting News:
WHT Membership
WHT Membership



 

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?