stuffradio
01-19-2006, 04:32 AM
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
Burhan
01-19-2006, 05:55 AM
Google for 'mod_rewrite tutorials'. For your specific case:
RewriteRule ^myblog.com/(.*?)$ myblog.com/blog.php?u=$1
extras
01-21-2006, 03:18 AM
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
stuffradio
01-21-2006, 03:40 AM
know where I can get a tutorial on this?
flann
01-21-2006, 04:35 AM
try this http://www.tedpavlic.com/post_apache_rewriting_examples.php
Burhan
01-21-2006, 06:43 AM
know where I can get a tutorial on this?
Try the URL Rewriting Guide (http://httpd.apache.org/docs/2.0/misc/rewriteguide.html) from the fine folks at Apache (also available with your local Apache install if you have the documentation installed).
extras
01-21-2006, 12:01 PM
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 ... >)
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.