Mod_Rewrite Help

Started by Chrono [email protected] June 4th, 2005 6:59 PM
  • 544 views
  • 8 replies
Seen March 14th, 2008
Posted March 4th, 2006
576 posts
18.2 Years
Can some one teach me mod_rewrite to rewrite my PHP URLs in Html? I did read a tutorial in phpfreaks website but I am not that knowledgeable in all these matters. So, can some one post it here about how to do it? Thank you very much!

One mroe doubt
<?php
   if (!$id) {
   $id = "main";
   $include = $id . ".txt";
   }
   else {
   $include = $id . ".html";
   }
   if (is_file($include) == "1") {
           include $include;
   }
   else {
   include "404.txt";
   }
   ?>
If I change this to

<?php
   if (!$page) {
   $page = "main";
   $include = $page . ".txt";
   }
   else {
   $include = $page . ".html";
   }
   if (is_file($include) == "1") {
           include $include;
   }
   else {
   include "404.txt";
   }
   ?>
Can I use index.php?page=blahblah.

Also what should my cutenews archives file is a .php file . Since my include tag includes only HTML files, what should I do to make it show .php files?

~ CC

~ CC
Age 62
Male
Melbourne, Australia
Seen April 26th, 2018
Posted June 9th, 2014
11,439 posts
19.7 Years
I see your pages are things like http://pokedrome.info/index.php?id=blah

So what you need to do is:

Open or create your .htaccess file (this is a text file named .htaccess) in your public_html directory.

Add the following lines of code to it:
RewriteEngine On
Options +FollowSymlinks
RewriteRule ^(.*).php /index.php?id=$1
See if that works.


"One reason why mathematics enjoys special esteem, above all other sciences, is that its laws are absolutely certain and indisputable, while those of other sciences are to some extent debatable and in constant danger of being overthrown by newly discovered facts."
Albert Einstein

"What science can there be more noble, more excellent, more useful for men, more admirably high and demonstrative than mathematics."
Benjamin Franklin

"Mathematics, rightly viewed, possesses not only truth, but supreme beauty – a beauty cold and austere, like that of sculpture, without appeal to any part of our weaker nature, without the gorgeous trappings of paintings or music, yet sublimely pure and capable of a stern perfection such as only the greatest art can show."
Bertrand Russell

avatar and signature by FoxHound

ANNOY ME AT YOUR PERIL. I am becoming increasingly tired of the unmanly elitism and closed-mindedness of certain members who shall remain unnamed.
Seen March 14th, 2008
Posted March 4th, 2006
576 posts
18.2 Years
Add the following lines of code to it:
RewriteEngine On
Options +FollowSymlinks
RewriteRule ^(.*).php /index.php?id=$1
I added the exact code you gave me in the .htaccess file but when I try to open my site I encounter 500 Internal server errors. Is it due to my host or anything. I also saw phpfreaks and added this code
RewriteEngine On
RewriteRule ^/(.*).php/index.php?id$1
but with no avail.

~ CC1
Age 62
Male
Melbourne, Australia
Seen April 26th, 2018
Posted June 9th, 2014
11,439 posts
19.7 Years
*giggle* 500 errors are VERY familiar to me when it comes to mod_rewrite. What host are you on?


"One reason why mathematics enjoys special esteem, above all other sciences, is that its laws are absolutely certain and indisputable, while those of other sciences are to some extent debatable and in constant danger of being overthrown by newly discovered facts."
Albert Einstein

"What science can there be more noble, more excellent, more useful for men, more admirably high and demonstrative than mathematics."
Benjamin Franklin

"Mathematics, rightly viewed, possesses not only truth, but supreme beauty – a beauty cold and austere, like that of sculpture, without appeal to any part of our weaker nature, without the gorgeous trappings of paintings or music, yet sublimely pure and capable of a stern perfection such as only the greatest art can show."
Bertrand Russell

avatar and signature by FoxHound

ANNOY ME AT YOUR PERIL. I am becoming increasingly tired of the unmanly elitism and closed-mindedness of certain members who shall remain unnamed.
Age 62
Male
Melbourne, Australia
Seen April 26th, 2018
Posted June 9th, 2014
11,439 posts
19.7 Years
Because it may have a script like PHPSuExec which causes the errors installed.


"One reason why mathematics enjoys special esteem, above all other sciences, is that its laws are absolutely certain and indisputable, while those of other sciences are to some extent debatable and in constant danger of being overthrown by newly discovered facts."
Albert Einstein

"What science can there be more noble, more excellent, more useful for men, more admirably high and demonstrative than mathematics."
Benjamin Franklin

"Mathematics, rightly viewed, possesses not only truth, but supreme beauty – a beauty cold and austere, like that of sculpture, without appeal to any part of our weaker nature, without the gorgeous trappings of paintings or music, yet sublimely pure and capable of a stern perfection such as only the greatest art can show."
Bertrand Russell

avatar and signature by FoxHound

ANNOY ME AT YOUR PERIL. I am becoming increasingly tired of the unmanly elitism and closed-mindedness of certain members who shall remain unnamed.
Age 62
Male
Melbourne, Australia
Seen April 26th, 2018
Posted June 9th, 2014
11,439 posts
19.7 Years
Hm..... is your .htaccess file in the right folder? skds, if you work for Mihopa, could you have a look at it for him then?


"One reason why mathematics enjoys special esteem, above all other sciences, is that its laws are absolutely certain and indisputable, while those of other sciences are to some extent debatable and in constant danger of being overthrown by newly discovered facts."
Albert Einstein

"What science can there be more noble, more excellent, more useful for men, more admirably high and demonstrative than mathematics."
Benjamin Franklin

"Mathematics, rightly viewed, possesses not only truth, but supreme beauty – a beauty cold and austere, like that of sculpture, without appeal to any part of our weaker nature, without the gorgeous trappings of paintings or music, yet sublimely pure and capable of a stern perfection such as only the greatest art can show."
Bertrand Russell

avatar and signature by FoxHound

ANNOY ME AT YOUR PERIL. I am becoming increasingly tired of the unmanly elitism and closed-mindedness of certain members who shall remain unnamed.