1

I have a page which is www.example.com/page_name.php?var1=dynamic_var1&var2=dynamic_var2

I want to use .htaccess file to make it look like this www.example.com/page_name/dynamic_var1/dynamic_var2

I have tried this so far

RewriteRule ^page_name/(.*)/(.*)$ page_name.php?var1=$1&var2=$2 [NC]

and the problem is when this is going to database it goes like this

SELECT * FROM table_name WHERE id=dynamic_var1/dynamic_var2.php/dynamic_var1 LIMIT 1

and i also tried this

RewriteRule page_name/(\w+)/(\w+) page_name.php?var=$1&var2=$2

it is loading the page but without any pictures or css file or anything, and when i used firebug it said that it failed to load the URL given.

and when i tried this

RewriteRule ^page_name/(\w+)/(\w+)$ page_name.php?var=$1&var2=$2

It gave me internal server error

Thanks in advance,

1 Answer 1

1

Don't try split the URL from within the .htaccess file. Why don't you try simply passing the entire query string to your index.php or any other script you want and parse the request there...

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

A much easier way would be to simply redirect all the requests into an index.php file that does something like this -

index.php -

Given http://yourdomain.com/user/123

$originalURL = $_GET['url'];
$URLParts = explode('/',$originalURL);

Now you have inside of $URLParts

Array (
 'user',
 '123'
)

Now you can easily place these values in your SQL query.

Watch out for SQL injection though! always use mysql_real_escape_string() and make sure to sanitize any incoming data...

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

1 Comment

Thanks a lot for your answer you really saved the day, only 9 mins left to accept the answer

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.