Help with my .htaccess to create SEF....little lost

Hello All:

I am trying to create my URL’s to be SEF and I am a little lost. First off let me say that I know that my Rewrite_mod is on because I did the simple test laid out here,

Ok, so I write this in my htaccess file -

RewriteEngine On

RewriteRule /(.*)/(.*)/$ info_page.php?page_id=$1&product=$2

and in that referenced page called “info_page.php” I have this mysql statment to query

$sql = "SELECT * FROM info_page where page_id = $selectedPageId";

$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());

I have been working on this for the better part of 2hrs now and I am new to mod_rewrite, or at least trying to dynamically create URL’s in .htaccess that is.

Any help or advice would be greatly appreciated.


The URL info_page.php?page_id=$1&product=$2

would populate $_GET[‘page_id’] and $_GET[‘product’]

What’s $selectedPageId?

I did not include that in the php code by accident, here is the whole thing.

if (!isset($_GET[‘id’])){
$selectedPageId = 0;
$selectedPageId = $_GET[‘id’];
$PHP_SELF=“”; // for navigation

//get page info
$sql = “SELECT * FROM info_page where page_id = $selectedPageId”;

$result = mysql_query($sql) or die(mysql_error());
$row = mysql_fetch_array($result) or die(mysql_error());


sorry about that.

There is no $_GET[‘id’] either, you defined the query string as having page_id and product parameters

maybe I am going about this all wrong, am I headed in the right direction if I want to change dynamic URL’s to look like Static ones for SEF purposes?

I feel like I confused myself somwhere along the way.

RewriteRule /(.*)/(.*)/$ info_page.php?page_id=$1&product=$2

This means that a URL matching the pattern on the left will be handled by the URI on the right.

So a request for

will be handled as if the request was to

Just as if that URL was what the user actually typed, $_GET[‘page_id’] and $_GET[‘product’] would be populated from the query string, with “drinks” and “pepsi” as values. You could name them whatever you want, you write the RewriteRule.

Thanks Dan for the help,

I think I am going to have to go back and learn more about mod_rewrite to fully understand this all and what I want to do to complete this.

thanks again,



Dan’s been giving you good information. If you need to learn a little more, check the tutorial linked in my signature as it’s helped members with their mod_rewrite for years.



Thanks DK,

Yeah I appreciated Dan’s stuff but I think I need to go back to basics for a refresher so I can actually walk this walk. :smiley:

Also, the link in my original post was your site that I found on the issue, so thanks again,



I am back and I have better questions with more detail this time on what I am doing, now that I know what I am talking about… or at least I hope I do. :smiley:

So in my .htaccess I have the following:

RewriteRule ^(.*)/$ /aroma/info_page.php?&page_id=$1 [L] 

and from what I learned over the past 2 days of reading, is that I have the ^(.*)/$ part pulling the original uri and then the /aroma/info_page.php?&page_id=$1 [L] telling the server what to change.

I then have in my page called info_page.php this sql statement to pull from the db to replace the uri with information from the db -

$sql = "SELECT * FROM info_page where page_id = $page_id";

I am not that fluent in sql so I am not sure I got that 100%

If there is any additional advice that someone can give me or point me in a direction as to what I might be doing wrong, it would be greatly appreciated.



Goodie! :Partier: More questions! :lol:

RewriteRule ^(.*)[COLOR="Red"]/[/COLOR]$ [COLOR="Magenta"]/[/COLOR]aroma/info_page.php?&page_id=$1 [L] 

ARGH! More of the :kaioken: EVERYTHING :kaioken: atom!

Okay, if you’re sure that ([a-zA-Z]+) won’t do it for you, yes, your code will redirect from {EVERYTHING/NOTHING}/ to the server’s root/aroma/info_page.php script. Just know that, because you’re already in the website’s root directory, you do NOT need the leading / in the redirection AND Apache MAY decide you want the server’s root, not the website’s root, DO NOT USE THE LEADING / IN THE REDIRECTION!

$sql = "SELECT * FROM info_page where page_id = '$page_id'";

Because $page_id is a string (unless you used the intvalval() function on it), you MUST enclose it in single quotes. “Close enough for government work” does not apply when coding! :smiley:



That also assumes PHP’s register_globals setting is enabled, otherwise you need to use $_GET[‘page_id’], as $page_id isn’t created for you automatically

Thanks DK, I knew you would love the more questions. :wink:

I appreciate your time in helping me understand this all as I venture forward into this new territory.

I think I got it now.


Thank you also for your addition and help with the matter.



Dan was correct about that (super_globals) except that it SHOULD be disabled as that’s a security problem that PHP has addressed by merely disabling it by default. I had made the assumption that you’d already gotten the $page_id variable with code similar to:

if (isset($_GET['page_id'] && !empty($_GET['page_id'])) $page_id = $_GET['page_id'];

In other words, if you don’t test that it exists, PHP will throw an error; if it’s a null value, your query will be looking for the null (which should not exist). ALWAYS look for ways that someone can break your script when dealing with inputs like this!

:award: Kudos to Dan for adding this to your thread.



Thanks again DK!

Yeah I checked that before when he mentioned it, and they were indeed off.

I am having a hard time getting this to work but I am determined to make it work by this weekend.

thank again for the help


Keep posting about the problem and lightning might strike!