Forum Moderators: phranque

Message Too Old, No Replies

.htaccess 404 query string

eg example.com/user/1 instead of example.com/?user=1

         

blakek

11:03 am on Apr 10, 2007 (gmt 0)

10+ Year Member



Hi,

I have seen websites that say for browsing a members profile its example.com/user/1 instead of eg example.com/index.php?user=1

I was wondering how they do this?

Is it with .htaccess mod rewrite or something?

I made my own by playing around. Files below:

.htaccess:
ErrorDocument 404 /index.php

index.php:
$qs = split("/",substr($_SERVER['REQUEST_URI'],1,strlen($_SERVER['REQUEST_URI'])));
$queryString = array();
for($i=0;$i<count($qs);$i++){
if($i%2==0){
$queryString[$qs[$i]] = $qs[$i+1];
}
}

If you want to see this in action you can view it here:
<snip>

and i have printed the array to the screen. This acts as i want it to, but then i viewed the headers via:
http://www.example.com/user/1/jump/comments

And it comes up with "HTTP Status Code: HTTP/1.1 404 Not Found". It still does work, but i dont think this is the correct way to implement what i want.

Now if i go to the domain via this link:
http://www.example.com/index.php/user/1/jump/comments

and check the headers again:
<snip>
it is correct "HTTP Status Code: HTTP/1.1 200 OK"

So if anyone knows of a better way to implement this or change what i have done or do this via the .htaccess a better way your help would be much appreciated.

Thanks,
Blake

[edited by: eelixduppy at 12:24 pm (utc) on April 10, 2007]
[edit reason] removed specifics [/edit]

blakek

1:29 pm on Apr 10, 2007 (gmt 0)

10+ Year Member



Well i found the answer to my own question browsing around the forum.

Its done in the htaccess file.

If you use this for your htaccess file:
RewriteEngine on
RewriteRule ^(.*)$ index.php?$1 [QSA,L]

It works properly and gives you the "HTTP Status Code: HTTP/1.1 200 OK" header :)

If anyone has thing to say on how to improve or recommend anything would be gladly appreciated.

Cheers,

Blake

jdMorgan

1:30 pm on Apr 10, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Blake, and welcome to WebmasterWorld!

This thread [webmasterworld.com] from our forum library, will help you get started.

You most definitely DO NOT want to use an ErrorDocument handler to serve normal requests on your site! You will confuse the search engines, and likely suffer a lot of ranking damage as a result.

Jim