JasonO Posted January 27, 2010 Share Posted January 27, 2010 Hey everyone, Currently I have the following mod_rewrite: RewriteEngine On RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1 [L] At the moment this converts any URL in the following format: http://domain.com/pagename to http://domain.com/index.php?page=pagename Works great! However, I need to get a 2nd parameter into my URL, but no matter how much I read on it and how much I tweak it (constant server errors etc) I can't get the following: http://domain.com/firstpage/secondpart to end up as http://domain.com/index.php?page=firstpage&act=secondpart Anyone able to point me down the right path? It's driving me mad! :-\ This is the closest I think I've got, but still server error. RewriteEngine On //RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1 [L] RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9]+)$ /index.php?page=$1&act=$2 RewriteRule ^([a-zA-Z0-9-]+)$ /index.php?page=$1 Regards, Jason Quote Link to comment https://forums.phpfreaks.com/topic/189943-expanding-my-mod_rewrite/ Share on other sites More sharing options...
wildteen88 Posted January 27, 2010 Share Posted January 27, 2010 This is causing the error //RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1 [L] You use # to comment out lines, not // Quote Link to comment https://forums.phpfreaks.com/topic/189943-expanding-my-mod_rewrite/#findComment-1002542 Share on other sites More sharing options...
JasonO Posted January 27, 2010 Author Share Posted January 27, 2010 Yeah, I figured that out after posting. Couldn't edit it though and didn't want to double post. I've managed to not get an error to show, although now I just get a 404 error error with a 2nd variable. I actually want a 3rd one possible too if I can. RewriteRule ^([a-zA-Z0-9-]+)/?$/^([a-zA-Z0-9]+)/?$ /index.php?page=$1&act=$2 RewriteRule ^([A-Za-z0-9-]+)/?$ index.php?page=$1 [L] I keep playing around with the symbols to try and get it to work but no joy Quote Link to comment https://forums.phpfreaks.com/topic/189943-expanding-my-mod_rewrite/#findComment-1002606 Share on other sites More sharing options...
wildteen88 Posted January 28, 2010 Share Posted January 28, 2010 This is should work fine RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9]+)/?$ /index.php?page=$1&act=$2 [L] RewriteRule ^([a-zA-Z0-9-]+)/?$ /index.php?page=$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/189943-expanding-my-mod_rewrite/#findComment-1003219 Share on other sites More sharing options...
JasonO Posted January 28, 2010 Author Share Posted January 28, 2010 Perfect. Learnt a lot about mod_rewrite now. Thanks very much for your help Quote Link to comment https://forums.phpfreaks.com/topic/189943-expanding-my-mod_rewrite/#findComment-1003288 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.