flatlander Posted August 10, 2011 Share Posted August 10, 2011 xampp / php 5.3 I've used the chapter 2 "Modularizing a web site" and it works like a charm. However I was wanting to use htaccess to turn 'http://localhost/website/index.php?p=about' into 'http://localhost/website/about'. I can't get it to work here but I have used this simple htaccess before and it works fine on another website I have and for other files on my localhost. RewriteEngine On RewriteRule ^([a-zA-Z0-9]+)$ index.php?p=$1 RewriteRule ^([a-zA-Z0-9]+)/$ index.php?p=$1 with the htaccess placed in the same directory as index.php and p is the same p in the example on page 62 or 64. Does anyone know what I can do to get this to work, from the things I've read it should produce the url I need. Thanks for any help S Link to comment Share on other sites More sharing options...
Larry Posted August 11, 2011 Share Posted August 11, 2011 You should confirm that .htaccess files are allowed in your configuration, which is to say that there's an allow override directive for that directory in your httpd.conf file. Link to comment Share on other sites More sharing options...
flatlander Posted August 11, 2011 Author Share Posted August 11, 2011 Thanks for the reply Larry There's <Directory "C:/xampp/htdocs"> AllowOverride All in the httpd.conf file. This is really odd to me because this same, more or less(member is used instead of p), rewrite works in another folder. Link to comment Share on other sites More sharing options...
Larry Posted August 12, 2011 Share Posted August 12, 2011 What folder is your .htaccess file in? Is it the C:\xampp\htdocs\website folder? Link to comment Share on other sites More sharing options...
flatlander Posted August 13, 2011 Author Share Posted August 13, 2011 It's in the same folder as index.php http://localhost/ed/5advan/chp2work/ullmans-temp/index.php Thanks Link to comment Share on other sites More sharing options...
Jonathon Posted August 13, 2011 Share Posted August 13, 2011 From my experience it's a lot harder to to work with .htaccess files when they're not in the root folder. I would try to do this example in your http://localhost/ folder. Link to comment Share on other sites More sharing options...
flatlander Posted August 13, 2011 Author Share Posted August 13, 2011 Thanks Johnathon I tried RewriteEngine On RewriteRule ^([a-zA-Z0-9]+)ed/5advan/chp2work$ index.php?p=$1 RewriteRule ^([a-zA-Z0-9]+)ed/5advan/chp2work/$ index.php?p=$1 RewriteEngine On RewriteRule ^([a-zA-Z0-9]+)/ed/5advan/chp2work$ index.php?p=$1 RewriteRule ^([a-zA-Z0-9]+)/ed/5advan/chp2work/$ index.php?p=$1 With no luck. If someone has done this exercise can they give it a try on the standard chapter 2 download, that's what I'm using, if it works on their computer I'll know its me. Thanks SJ Link to comment Share on other sites More sharing options...
Jonathon Posted August 13, 2011 Share Posted August 13, 2011 That doesn't look like the rules are directed for the root. Sorry, my first message was probably misleading i'd just woken up! What i meant was, put the files in the root and also the .htaccess file Link to comment Share on other sites More sharing options...
Larry Posted August 15, 2011 Share Posted August 15, 2011 You can leave the .htaccess file in that folder, but I would recommend adding the RewriteBase directive, after turning on the engine, to acknowledge all the subdirectories. Link to comment Share on other sites More sharing options...
flatlander Posted November 8, 2011 Author Share Posted November 8, 2011 Okay here is my "Duh report", it's had been about three months since I messed with this and I decided I'd try again today and of course it worked when I saw what I had done. Larry has <li><a href="index.php?p=that">That</a></li> in the menu and three months ago I had left it like that while I looked for the problem. Today when I changed the link to <li><a href="that">That</a></li> it worked like a charm. So the htaccess would have worked all along, anyway thanks for the help. Link to comment Share on other sites More sharing options...
Larry Posted November 9, 2011 Share Posted November 9, 2011 Excellent. Glad it's working and thanks for letting us know. Link to comment Share on other sites More sharing options...
Recommended Posts