Jump to content

Recommended Posts

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.