PDA

View Full Version : Mod rewrite question (hiding fancy URL'S)


Andy14
07-29-2006, 03:48 AM
Hi there,

My name is Andy, I’m 17 – a long time fan, first time poster.

I was wondering if someone PHP-savy would be able to help me with, what I hope, is a simple problem to do with mod rewriting. Usually, I’m pretty good at picking up the errors, but I’m rather new to it all – and I just can’t seem to figure out the problem. Any help would be most appreciated!

I have coded my website with PHP for easy content management. My files are all .html files but I use PHP to dynamically include them into my layout, they are in the form of:

Mywebsite.com/?ID=contactus
Mywebsite.com/?ID=fans/downloads (where downloads.html is a file in the ‘fans’ folder)
Mywebsite.com/?ID=movies/reviews/staffreviews etc.

My home page is set to be included by default, so: Mywebsite.com loads the home page (home.html)

Of course, when I was a naïve young teenager, first starting the site, I thought it would be really cool to make the URL all fancy and technical sounding (“site.com/?ID=aboutus&pID=3&section=zzz”). After running the site for three years now, I simply want to have it as simple as possible, so that readers can easily find pages, and search engines can easily pick them up. I want to go as simple as possible to make it easier for my readers. A few Google searches told me about the “mod rewrite” tool which could be used to hide URLS. I read half a dozen tutorials, and had a play for about four hours, yet I’m getting a few errors. This is the code that I am using in my .htaccess file (I gathered from a few tutorials that this was the best way to go).


RewriteEngine On
RewriteRule ^(.*) index.php?ID=$1


The aim of that code was to get rid of the ?ID= function, so that
Mywebsite.com/?ID=contactus becomes Mywebsite.com/contactus
Mywebsite.com/?ID=fans/downloads becomes Mywebsite.com/fans/downloads
Mywebsite.com/?ID=movies/reviews/staffreviews becomes Mywebsite.com/movies/staffreviews etc.

With this, however, my entire site is filled with broken images, 404 errors etc. If I put a secondary folder in there, it works: i.e

RewriteEngine On
RewriteRule ^pages/(.*) index.php?ID=$1

(makes Mywebsite.com/?ID=contactus becomes Mywebsite.com/pages/contactus and mywebsite.com/?ID=games/flashgames become mywebsite.com/pages/games/flashgames)

It even works with only the smallest thing being added, such as another slash, but it won't run without something else. I.e

RewriteEngine On
RewriteRule ^/(.*) index.php?ID=$1

(makes Mywebsite.com/?ID=contactus becomes Mywebsite.com//contactus and mywebsite.com/?ID=games/flashgames become mywebsite.com//games/flashgames)

Is there any way I can make this work so that I can simply hide the ?ID= (yet not make it screw up the home page) on my site. I don’t see what I am doing wrong, and would really love to get this neat trick to work! I have set all images to their absolute paths, and have converted all my internal links to their full URLS, so I think once I get my .htaccess code sorted, it should all fall into place.

Does anyone know what I’m doing wrong? Or is there a trick I am missing (or can this simply not be done :() ?

Any help would be kindly welcomed!

Sincerely,
Andy