• 0

Using PHP for Site Templates


Question

This is been bugging me, and I can't seem to find an answer on Google or a search here, because it's hard to explain (and therefore, search for).

I know there's a PHP setting or function where you can have http://www.mydomain.com/abc/ actually go to http://www.mydomain.com/page.php?id=abc. I don't think it's a page redirect or anything, because there won't actually be a '/abc/' directory on the server. I can't remember the name of that function/setting... does anyone have any ideas, or am I being a little confusing?

Thanks!

Link to comment
https://www.neowin.net/forum/topic/419087-using-php-for-site-templates/
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Use a .htaccess file for this. Example -

<IfModule mod_rewrite.c>
RewriteEngine On
Options +FollowSymlinks
RewriteBase /

RewriteRule ^?(.*)/ /page.php?id=$1 [QSA,L]
</IfModule>

I'm no pro with .htaccess, but that should work. So, if you went to site.com/whatever it would use /page.php?id=whatever, same goes for /abc and etc.

  • 0

By the way, just for clarification, this is not a function of PHP. It's called mod_rewrite and is a module for the Apache web server. You can achieve a similar effect in PHP, using just PHP (for example, if you do not have mod_rewrite installed on your server, and do not have access to install it); the resulting links would look basically the same, just using slashes instead of the ? and & (for instance, /product.php?id=123&page=description could be become /product.php/123/description/).

  • 0

It's a similar effect. So, instead of your links looking like:

http://www.example.com/product/123/description

they would look like this:

http://www.example.com/product.php/123/description

Notice that the second example contains the actual file name of the script (product.php). You are still giving the effect of SE friendly URLs by not using the ? to denote the query string and &s to separate variables. Instead you use the slash. All you would do, instead of using the $_GET array to access the variables, you would use the $_SERVER['QUERY_STRING'] or $_SERVER['REQUEST_URI'] variables to get the query string or full URI respectively, and then do some parsing magic in your script to split it into meaningful and usable pieces.

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.