Results 1 to 7 of 7
Thread: Friendly urls
Hybrid View
-
01-19-2006, 04:32 AM #1Web 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
-
01-19-2006, 05:55 AM #2Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
Google for 'mod_rewrite tutorials'. For your specific case:
RewriteRule ^myblog.com/(.*?)$ myblog.com/blog.php?u=$1
-
01-21-2006, 03:18 AM #3Web Hosting Master
- Join Date
- Aug 2005
- Location
- Canada
- Posts
- 862
RewriteRule ^myblog.com/(.*?)$ myblog.com/blog.php?u=$1
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
-
01-21-2006, 03:40 AM #4Web Hosting Guru
- Join Date
- Dec 2005
- Posts
- 326
know where I can get a tutorial on this?
-
01-21-2006, 06:43 AM #5Web Hosting Master
- Join Date
- Jul 2003
- Location
- Kuwait
- Posts
- 5,104
Originally Posted by stuffradio
-
01-21-2006, 12:01 PM #6Web Hosting Master
- Join Date
- Aug 2005
- Location
- Canada
- Posts
- 862
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]
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.
-
01-21-2006, 04:35 AM #7Newbie
- Join Date
- Jan 2006
- Posts
- 22