robolist Posted November 2, 2012 Share Posted November 2, 2012 I have successfully created my mod_rewrite rule to change all dynamic URLs on the top level of the site, but now i need to create a rule for a second level, and i think later down the line i might need a second, second level of rewrites. At the moment i have this RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^(.+)$ index.php?subj=$1 And this helps to change /index.php?subj=home to /home as it does for all other pages such as /contact /about /events and so on. But now I have created sub pages under events and therefore need to change /events.php?event=event-name to events/event-name. But when i add another rule it messes up the whole site. What i tried to do is this RewriteEngine on RewriteCond %{SCRIPT_FILENAME} !-d RewriteCond %{SCRIPT_FILENAME} !-f RewriteRule ^(.+)$ index.php?subj=$1 RewriteRule ^events/(.+)$ event.php?event=$1 I've even tried it with [L] flags after the Rewrite rules, but nothing seems to work, I would really appreciate it if someone can show me the best way to do this as nothing seems to work. Many thanks in advance Link to comment https://forums.phpfreaks.com/topic/270209-multiple-mod_rewrite-rules-not-working/ Share on other sites More sharing options...
beyzad Posted November 2, 2012 Share Posted November 2, 2012 Hi. Im not sure, but i think this is because in your first rule, you redirected ALL urls. Try to expand you conditions. Link to comment https://forums.phpfreaks.com/topic/270209-multiple-mod_rewrite-rules-not-working/#findComment-1389756 Share on other sites More sharing options...
jcbones Posted November 2, 2012 Share Posted November 2, 2012 Try putting your events rule above your index rule. The rule with the broadest brush should reside at the bottom so it is parsed last. Link to comment https://forums.phpfreaks.com/topic/270209-multiple-mod_rewrite-rules-not-working/#findComment-1389792 Share on other sites More sharing options...
robolist Posted November 3, 2012 Author Share Posted November 3, 2012 Try putting your events rule above your index rule. The rule with the broadest brush should reside at the bottom so it is parsed last. I tired that, but it didnt work. Nothing worked when i put the event rule on top, in fact the site was all messed up. Im not sure, but i think this is because in your first rule, you redirected ALL urls. Try to expand you conditions. Thanks, that makes a lot of sense. Can you please advise me of the best solution? I've tried so many variations without any luck. Link to comment https://forums.phpfreaks.com/topic/270209-multiple-mod_rewrite-rules-not-working/#findComment-1389842 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.