Help with parsing URL

LotsOfZeros

^^^ Bi-Winning ^^^
Feb 9, 2008
4,648
118
0
www.makemoniesonline.com
I would like to clean up my links like this:
hxxp://www.site.com/user

instead of doing this:
hxxp://www.site.com/index.php?id=user

My assumption is that I would have to code my index.php file to parse the URL and redirect to the second one but I don't actually have a folder named 'user' so how do I make this work dynamically without it giving a 404?
 


One way would be to put a couple rules like this in your htaccess file:

RewriteRule ^(.+)$ /index.php?id=($1)

That internally rewrites /user to /index.php?id=user (no redirect occurs). Then you can change all your internal links to use the /user format.

RewriteCond %{QUERY_STRING} id=(.+)
RewriteRule ^index\.php$ http://www.site.com/%1 [R=301,L]

And that 301 redirects the old URLs to the new ones.

Untested, but that's the general idea.
 
mod_rewrite in an .htaccess

Like how wordpress does it using friendly urls:

Code:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

note how if the file or folder does not exist it sends everything to the index.php where it can then parse the $_SERVER['QUERY_STRING'];
 
One way would be to put a couple rules like this in your htaccess file:

RewriteRule ^(.+)$ /index.php?id=($1)

That internally rewrites /user to /index.php?id=user (no redirect occurs). Then you can change all your internal links to use the /user format.

RewriteCond %{QUERY_STRING} id=(.+)
RewriteRule ^index\.php$ http://www.site.com/%1 [R=301,L]

And that 301 redirects the old URLs to the new ones.

Untested, but that's the general idea.

Won't work unless you put RewriteEngine On at the top and maybe a few other commands such as the base location. Also without checking to see if the file/folder already exists you run the risk of javascript, images, css, etc failing because everything keeps being sent to the index.php
 
Yes, thanks. These conditions make it so it only rewrites if the file or directory doesn't exist.

RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?id=($1)

I didn't mention RewriteEngine On and RewriteBase b/c everyone's set up is different and they might already be in there. But he's right you may need them.
 
If you do need to switch hosts, avoid the first one on that list (appliedi.net).

One that's not on the helicontech list, but I can recommend based on my experience them, is hxxp://infosaic.com/