exhaler Posted July 2, 2010 Share Posted July 2, 2010 Hi, i just starting to use mod_rewrite on a website, and having a hell of a time to get to work. using xampp, i checked that the mod_rewrite is enabled in the phpinfo() and replaced AllowOverride None to AllowOverride All in the httpd.conf. placed .htaccess file in the directory with the following code: Options +FollowSymLinks RewriteEngine on RewriteRule event_info/id/(.*)/ event_info.php?id=$1 what i want to do is change the url from: http://localhost/test/event_info.php?id=1 to http://localhost/test/event_info/id/72/ thanks for the help Quote Link to comment https://forums.phpfreaks.com/topic/206504-xampp-and-mod_rewrite/ Share on other sites More sharing options...
trq Posted July 2, 2010 Share Posted July 2, 2010 phpinfo() (funnily enough) provides information about php's configuration. mod_rewrite has nothing at all to do with php. Is this .htaccess file within the test directory? Quote Link to comment https://forums.phpfreaks.com/topic/206504-xampp-and-mod_rewrite/#findComment-1080206 Share on other sites More sharing options...
exhaler Posted July 2, 2010 Author Share Posted July 2, 2010 yes, also the mod_rewrite is un-commented in the httpd.conf Quote Link to comment https://forums.phpfreaks.com/topic/206504-xampp-and-mod_rewrite/#findComment-1080207 Share on other sites More sharing options...
cags Posted July 2, 2010 Share Posted July 2, 2010 You don't really explain what the problem is, assumably it's not working for you. Firstly your understanding (like 90% of peoples) seems to be a little backwards. The first half of a RewriteRule is what matches against what is requested by the clients browser i.e the address the user sees in the address bar. The second half corresponds to the file which you wish to show the user. Therefore assuming there are no errors in your rule, if you were to type http://domain/event_info/id/10 into the address bar, then the user would see the same page as if they typed in http://domain/event_info.php?id=10. This means that you need to change all URLs in your site to the 'pretty' format e.g. event_info/id/10. Secondly, ideally you will need to be more specific with your regular expressions. You should anchor the pattern at the start and the end and avoid using . as much as possible. Assuming an ID is numeric then I would use a rule along the lines of... RewriteRule ^event_info/id/([0-9]+)/?$ /event_info.php?id=$1 NB: The forward slash before the event_info may not be required, it depends on exactly where the rule is being written. If you get a 404 without it, try adding it in as I did. Quote Link to comment https://forums.phpfreaks.com/topic/206504-xampp-and-mod_rewrite/#findComment-1080209 Share on other sites More sharing options...
exhaler Posted July 2, 2010 Author Share Posted July 2, 2010 thanks cags for the explanation, however when i tried ur code nothing happens... the url stays as http://localhost/test/event_info.php?id=1. i get not errors my code or cags's code Quote Link to comment https://forums.phpfreaks.com/topic/206504-xampp-and-mod_rewrite/#findComment-1080213 Share on other sites More sharing options...
cags Posted July 2, 2010 Share Posted July 2, 2010 As I said, you are not understanding how it works. This mod_rewrite rule will not change your URL at all, that is not what making 'pretty URLs' is all about. It will simply Alias the address so you can access it with a different URL. If you can type http://localhost/test/event_info/id/1 into your address bar and see the same page as if you type http://localhost/test/event_info.php?id=1, then it is working fine. Quote Link to comment https://forums.phpfreaks.com/topic/206504-xampp-and-mod_rewrite/#findComment-1080215 Share on other sites More sharing options...
exhaler Posted July 2, 2010 Author Share Posted July 2, 2010 thanks for the clarification cags, and yes it does work http://localhost/test/event_info/id/1 shows the right page. how can i do the 'pretty URLs' thing?? or what should i write in order to get the above page if i wrote in the url http://localhost/test/event_info.php?id=1 thanks again Quote Link to comment https://forums.phpfreaks.com/topic/206504-xampp-and-mod_rewrite/#findComment-1080225 Share on other sites More sharing options...
cags Posted July 2, 2010 Share Posted July 2, 2010 You just need to make all the links on your site look like /event_info/id/1, not this /event_info.php?id=1. Quote Link to comment https://forums.phpfreaks.com/topic/206504-xampp-and-mod_rewrite/#findComment-1080227 Share on other sites More sharing options...
exhaler Posted July 2, 2010 Author Share Posted July 2, 2010 one final question (hopefully), the page i'm viewing doesn't get the css's or header's?? Quote Link to comment https://forums.phpfreaks.com/topic/206504-xampp-and-mod_rewrite/#findComment-1080234 Share on other sites More sharing options...
cags Posted July 2, 2010 Share Posted July 2, 2010 That's because you are using a relative path for src, which is no longer correct as the URL is seen as being in a different folder. I explained this to somebody else yesterday. http://www.phpfreaks.com/forums/index.php/topic,302823.0.html Quote Link to comment https://forums.phpfreaks.com/topic/206504-xampp-and-mod_rewrite/#findComment-1080236 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.