YourNameHere Posted February 5, 2010 Share Posted February 5, 2010 Hi, I am trying to start learning mod rewrite. I have read several blogs and other articles about it. They all have assumed knowledge that I don't. What I am wanting to achieve seems fairly simple. My directory structure looks like this. localhost/testServer/websiteName/ C:/xampp/htdocs/ - testServer - websiteName - index.php .htaccess I want the mod_rewrite to 'catch' urls from index.php and change them from index.php?tutorial=$1 to look like /websiteName/tutorial/$1 however, I have pasted the sample codes from different blogs in and it doesnt work at all. so I guess I am asking for someone to take a look and find my issue. ( I know through phpinfo() that the module is active) htaccess <IfModule mod_rewrite.c> RewriteEngine on RewriteRule index.php/([a-z]+) /websiteName/index.php?tutorial=$1 </IfModule> I renamed the htaccess file to htaccess from .htaccess Quote Link to comment https://forums.phpfreaks.com/topic/191096-understanding-the-basics/ Share on other sites More sharing options...
trq Posted February 6, 2010 Share Posted February 6, 2010 I renamed the htaccess file to htaccess from .htaccess You shouldn't have. Quote Link to comment https://forums.phpfreaks.com/topic/191096-understanding-the-basics/#findComment-1007691 Share on other sites More sharing options...
YourNameHere Posted February 6, 2010 Author Share Posted February 6, 2010 OK, even after renaming it back it isn't working. Quote Link to comment https://forums.phpfreaks.com/topic/191096-understanding-the-basics/#findComment-1007775 Share on other sites More sharing options...
cags Posted February 6, 2010 Share Posted February 6, 2010 What URL were you testing your RewriteRule with? It sounds very much to me like you have the concept back to front (like everyone seems to). Quote Link to comment https://forums.phpfreaks.com/topic/191096-understanding-the-basics/#findComment-1007833 Share on other sites More sharing options...
YourNameHere Posted February 6, 2010 Author Share Posted February 6, 2010 What URL were you testing your RewriteRule with? It sounds very much to me like you have the concept back to front (like everyone seems to). /websiteName/index.php?tutorial=something I want it to look like /websiteName/tutorial/something Quote Link to comment https://forums.phpfreaks.com/topic/191096-understanding-the-basics/#findComment-1007942 Share on other sites More sharing options...
cags Posted February 6, 2010 Share Posted February 6, 2010 So yes, you do have it back to front, the way mod_rewrite would generally work is you would make all your links on your site the latter of those two, then mod_rewrite will convert it back to the 'ugly' URL. In theory you could perhaps mod_rewrite in both directions (but it means anybody viewing links on your page will view the 'ugly' format), but anything after the question mark is a query string and as such will not work with the RewriteRule in the manner your attempting, you'd have to use something more along the lines of RewriteCond %{QUERY_STRING}. But you'd be much better off switching the two over. Quote Link to comment https://forums.phpfreaks.com/topic/191096-understanding-the-basics/#findComment-1007990 Share on other sites More sharing options...
YourNameHere Posted February 7, 2010 Author Share Posted February 7, 2010 ...switching the two over. Like so? RewriteRule /websiteName/index.php?tutorial=$1 index.php/([a-z]+) Edit: Never-mind, that didn't work. I think I missed your point. I tested it against this url: http://localhost/testServer/Majesticlicks.com/index.php?tutorial=lightBursts should look like: http://localhost/testServer/Majesticlicks.com/tutorial/lightBursts Quote Link to comment https://forums.phpfreaks.com/topic/191096-understanding-the-basics/#findComment-1008186 Share on other sites More sharing options...
cags Posted February 7, 2010 Share Posted February 7, 2010 You want all URLs to look like the second one right? So you need to make all URLs on your pages look like the second one. The RewriteRule is then used to rewrite all URLs of that format into the format the actual file is stored at. RewriteRule /testServer/Majesticlicks.com/[^/]+/[^/]+ /testServer/Majesticlicks.com/index.php?$1=$2 Therefore you are taking the URL you WANT and rewriting it to the ACTUAL URL. Quote Link to comment https://forums.phpfreaks.com/topic/191096-understanding-the-basics/#findComment-1008304 Share on other sites More sharing options...
YourNameHere Posted February 7, 2010 Author Share Posted February 7, 2010 thanks, I understand. Quote Link to comment https://forums.phpfreaks.com/topic/191096-understanding-the-basics/#findComment-1008455 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.