I thought I understood mod-rewrite after reading the sticky but I guess I don't. I have a script configured where it writes the friendly URLs to the page in this format as the entries are read from the DB: /interger/The-title-of-the-item.html where interger is the uniue id # of the row. sample: /1/The-title-of-the-item.html I want to rewite /1/The-title-of-the-item.html to view.php?id=1 so when the link (/1/The-title-of-the-item.html) is clicked the page view.php?id=1 is loaded and the browser displays Domain.com/1/The-title-of-the-item.html I certainly thought that: Options +FollowSymLinks Options +Indexes RewriteEngine On RewriteBase / RewriteRule ^/([0-9]+)/(.*)\.html$ /view.php?id=$1 [L] PHP: would work but it does not seem to. Or did I miss the boat completely?
That did not work either. I tried it again even though I thought I had already. At least we agree that the syntax is close to right. Any other takers?
The rule chadsmith gave is correct, do you have any error messages? That rule expects view.php to be in the root of the site, is that the case? if not try removing the / before view.php in the rule.
Guys I completely agree that it should be working but it is not. His rule was just my rule with the / removed. Since I was doing this only localhost I went ahead and uploaded the 3 files to the server. It did not work there either. Mod-rewite is enabled both on localhost and on the server. Sooner or later I will find some stupid something that is not right and then I will update the thread. I will also check the thread in case anyone has an inspiration.
The correct URL is written to the browser and the page is not found. Standard browser resource not found. If I use view.php?id=X the page loads fine. For testing and debugging I have dual links on the first page so that I can click either. So I assume the problem is in transferring the value of the id. I may turn on the Apache logs and see if that shows anything worth looking at but I won't do that tonight.
In that case, either the server is completely ignoring the rewrite or the path to view.php is wrong, so assuming the server isn't ignoring you, check the path to view.php is correct, try without the leading /. Logs should have more detail on what it's looking for and not finding.
I promised to update this thread when I found the answer. After examing the .htaccess files for scripts that worked and this one that did not, I determined that the problem was in the application of RewriteBase. When running a script on localhost using xammpp, where active dierctory is xampp/htdocs/dirname then RewriteBase needs /dirname/ in order for proper operation. Commenting out the line works just fine also. I have noted the problem and the solution as remarks in code below. I am sure there is a valid use for RewriteBase but not using it at all seems to be the easier choice. Options +Indexes Options +FollowSymlinks RewriteEngine on # rewrite base will need to be adjusted for use on server, most likely to / # localhost on xammpp, when active dierctory is xampp/htdocs/dirname then RewriteBase needs /dirname/ # or just don't use it at all. It seems to work fine without it also. # RewriteBase /news/ RewriteRule ^([0-9]+)/(.*)\.html$ view.php?id=$1 [L,NC] Code (markup): Here's hoping that this thread saves someone else from a fews hours of frustration some time.
COLBYT Good post. I am testing something similar and I am seeking help as it is not working. Moving a static site to a dynamic domain -each page individually. May be i can send you a private message for help?