MockY Posted August 9, 2012 Share Posted August 9, 2012 Before diving in to a new project, I created a small temporary one just to see how mod_rewrite works and what I need to do before proceeding The server is Ubuntu and I have the following enabled: sudo a2enmod rewrite As well as AllowOverride All in the default site, so technically, mod_rewrite should work just fine So let's say this projects is named reviews and will contain reviews of albums, movies, and such. It is also run locally. So the url to the project is http://localhost/reviews/ In the project, I created a file called albums.php which displays the specific album asked for, using an unique Id from the database. In other words, the URL looks like this when displaying all the info from album with Id 1: http://localhost/reviews/album.php?id=1 In the album.php file, I set a variable with the id with $_GET['id'] and then query the database. As you can tell, I made it as basic as possible just to demonstrate how things work and to more easily "fix" the issue. What I want to accomplish is this (to start with) http://localhost/reviews/album/1/ So for this to work, I created teh necessary .htaccess file in the reviews root directory with the following in it RewriteEngine On RewriteRule ^album/([0-9]+)/?$ album.php?id=$1 [NC,L] I also tried RewriteRule ^album/([0-9]+)/ /album.php?id=$1 But this does not work. When I query the database using the variable set by $_GET['id'], it fails as the variable is not set at all. This is somewhat logical as the id variable does no longer exists in the URL (there is no album.php?id=1 anymore). The resulting query is therefore SELECT * FROM albums WHERE Id= But this is what I thought the rewrite would take care of. I created an identical project (the structure) as the examples in this tutorial http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/ but no dice. What is it that I'm missing here? Do I need something else installed on my Ubuntu system? Quote Link to comment https://forums.phpfreaks.com/topic/266874-simple-example-fails-get-variable-no-longer-present-when-using-mod_rewrite/ 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.