1

I'm really new at mod_rewrite and i have been trying to figure this out but really stuck. p Here is my issue.

I have a page http://example.com/user/?s=81 ?s=81 is reading from user id in the db.

What i would like to have is a link
http://example.com/nookie

In the database i have a field called whatuser so on row 81 in that field i have user nookie

So what i would like is to read from databse what user it is in database and create easi url from it. i have also several php pages inside that user folder so i need to be able to link to them like

example.com/nookie/step1.php
example.com/nookie/step2.php
0

4 Answers 4

1

To my knowledge you can not query databases with mod_rewrite.

how about putting a PHP-script to /user/?s=81, that looks up the user's name in the db and then relocates the user to $url = "/$username"; see PHP's header function passing "Location: $url" to it.

Sign up to request clarification or add additional context in comments.

6 Comments

I guess it's should be posible to link to external php file from .htaccess and from there make a query to DB.
aww, all the downvoting. sorry for trying to help. my mistake. if what you are trying to say matches my suggestion, go for it. if you try to process the result of a php-script in a .htaccess file, don't bother. it won't work.
I'm not trying to process the result of php scriptin .htaccess file.. I've heard also its not possible. But i will try you solution when i get back home. Btw i did not vote it down ;)
well some did and didn't even have the balls to tell what bothered him. well, stackoverflow seems just like any other place on the internet. good luck!
Great answer! Combines rewrites and php output! You should patent the idea. I will use it for on-the-go creation of graphs: Rewrite to php if graph is not there, and then in php redirect again to let apache output the graph. Without your method, one has to output the graph in php, AND has to send output headers in php, and has to consider cdn and the lot again in php. The redirect should be 302 or 303, and header("Cache-Control: no-cache, must-revalidate"); is important to prevent cache problems.
|
0

The other possibility (that I haven't thought through too much :) ) is that you add an extra field to the database e.g. user_home = /nookie/. So the logon script grabs it when verifying account details and thats where you send them to on successful validation? No rewrites /extra scripts needed.

Comments

0

Here's what I would suggest: if your username is only alphanumeric chars, you could pass the nick to all your Php files, after an internal rewrite, in the GET query.

Something like:

RewriteRule /([a-zA-Z0-9]+)$ /user/?s=$1 [QSA,L]
RewriteRule /([a-zA-Z0-9]+)/(.*)$ /$2?s=$1 [QSA,L]

And then, just have the "mother of mother" classes in Php that check for a value "s" in the query string ($_GET) which checks in the database if the user exists. If the user doesn't exists, make a 404 in Php.

Comments

0

I have almost sorted it out and here is the solution so far: Here is the .htaccess row

RewriteRule ^([a-z0-9_-]+)$ user/?s=$1 [L,NC]

Then in the index file i have the following: $trafikskola_id = mysql_real_escape_string($_GET['s']);

$vilken_trafikskola = mysql_query("SELECT * FROM users where slug='$trafikskola_id'") or exit(mysql_error());

In the database i have create slug field and inside that on row 81 added nookie and my url looks like

http://mypage.com/nookie instead of http://mypage.com/user/?s=81 =))

However i have the issue that i can not have link http://mypage.com/nookie/ to have a forwardslash

And aswell non of my css - js - images are working.. Any ideas to solve those issues?

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.