homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

mod_rewrite HELP
to make dynamic PHP pages look static

 3:16 am on Jul 29, 2003 (gmt 0)


I've searched the forums and found a lot of mod-rewrite examples but I can't seem to find the one that I need. Can someone please show me how to write this.

I need a mod_rewrite that will make dynamic urls look static.


[mydomain.com...] (p.s. have 100's of CatID)

from requests for

Thanks a lot



 8:09 pm on Jul 29, 2003 (gmt 0)

Welcome to WebmasterWorld joetuv! :)

There are a number of threads discussing this already and we're not the Apache help desk! ;) We avoid redundent posts whenever possible and prefer to help you debug your code, not write it for you.

These pages should provide some good basics about your question to get you started:


 9:19 pm on Jul 29, 2003 (gmt 0)

I need a mod_rewrite that will make dynamic urls look static.

I think you are confuse about mod_rewrite...it doesn't make your dynamic URL look static but rather if somebody access your site say from [mydomain.com...] then mod_rewrite will convert this request into your acceptable dynamic URL say [mydomain.com...] otherwise the request would trigger a 404 error.

To make your dynamic URL look static, you have to hack the application/software that produces these dynamic URLs into seemingly static URL. This convertion has nothing to do with mod_rewrite.

The exact process on how to change for example [mydomain.com...] into [mydomain.com...] is dependent on the software you are using.

If there's a support board for your software, that's the best place to get an idea how to convert the URL, it's possible that somebody have develop the hack or module for that process.

Hope this help.



 4:01 am on Jul 30, 2003 (gmt 0)

Dear DaveAtIFG;

Thank you for the urls.

i have checked [evolt.org...]

and flowed the authors insrructions.

firstly modifing the .htaccess to process a file as a file.php

<Files name-of-file>
ForceType application/x-httpd-php

secound step; i used his function to expolde the url:

function processURI() {
global $REQUEST_URI;// Define our global variables

$array = explode("/",$REQUEST_URI);// Explode the URI using '/'.

$num = count($array);// How many items in the array?

$url_array = array();// Init our new array

for ($i = 1 ; $i < $num ; $i++) {// Insert each element from the
$url_array["arg".$i] = $array[$i];// request URI into $url_array
}// with a key of argN. We start $i
// at 1 because exploding the URI
// gives us an empty ref in $array[0]
// It's a hacky way of getting round it
// *:)

return $url_array;// return our new shiny array

// displayContent():

function displayContent($array) {
$section = $array["arg3"];// get the values out of the array and
$cat = $array["arg4"];// assign them.

$content = "content/" // cat together all our elements to
. $section // get a file name.
. "_"
. $cat
. ".php";

if (!file_exists($content)) {// Does the file exist?
$content = "error.php";// Nope, someone is playing around
} else {
include($content);// Yes, include the file

///////// END OF FUNCTIONS /////////////


// Init the page, run processURI and assign it.
$myarray = processURI();

now i am stuck at the third stage. how to send url's to the script to explode? anyone pleeeaase.


 4:29 am on Jul 30, 2003 (gmt 0)

Getting back to your original question:

First: Why /directory/CatID=3 when you can have just /directory/3/?
Of course, /directory/name_or_keyword would make even more sense.

Anyway -- these two lines in /directory/.htaccess
RewriteEngine on
RewriteRule ^([0-9]+)/?$ ViewCat.php?CatID=$1

[mydomain.com...] or
invisibly into
and work like that with every other number too.

If you have mod_rewrite on your server (you should), there's no need for complicated PHP.
Of course as Net_Wizard said you have to change all the links to point to the new alias address.


 5:31 am on Jul 30, 2003 (gmt 0)

Thanks c3oc3o,

I tried it but it's generating a 403 error.

I added this in my .htaccess:

RewriteEngine on
RewriteRule ^([0-9]+)/?$ ViewCat.php?CatID=$1

are there anything else that I need to add to this mod to be able to access the directory? and other files in the directory?



 2:33 pm on Jul 30, 2003 (gmt 0)

Hmm, it's working for me -- seems like you don't have mod_rewrite on your server.

If you have access to the server error logs, see whether it logs something like this:
[Tue Jul 29 16:18:46 2003] [alert] [client] /.htaccess: Invalid command 'RewriteEngine', perhaps mis-spelled or defined by a module not included in the server configuration

Or make a PHP page with phpinfo(); and ctrl+f that for "mod_rewrite". If it's not there, you don't have it unfortunately.


 5:20 pm on Jul 30, 2003 (gmt 0)

Options +FollowSymLinks
to your .htaccess may help if mod_rewrite is indeed available to you.

Some hosted sites require it in .htaccess before using mod_rewrite and some don't, depends on the server configuration.

Also, if you're new to mod_rewrite, you may find this intro [webmasterworld.com] useful.


 10:02 pm on Jul 30, 2003 (gmt 0)

Just added

Options +FollowSymLinks

and works great.

Thanks guys!


 9:29 pm on Jul 31, 2003 (gmt 0)

I have a similar problem. All links are pointing to www.site.com/index.html, and now I want to run a php script on that page. Can someone tell me how I should work it if I want to change the file to www.site.com/index.php, but keep all the links pointing at the static url?


 9:33 pm on Jul 31, 2003 (gmt 0)

Check out:



 10:17 pm on Jul 31, 2003 (gmt 0)

Thanks bcolflesh
Threads got moved around and I found: [webmasterworld.com...]
The only problem is that I want to run the script on the index.html page, and all of the other pages on the site have the same html extension. There are a lot of pages and I would really take a performance hit if they were all parsed for php code. I only want to run the script on the one page.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved