I have a site with a structure like this:
Root
- Folder1
- Folder2
- Folder3
For my root, I have a rewrite that sends root.com/index.php?id=12 to root.com/12 and that’s working fine.
However, I’d also like root.com/folder1/index.php?id=12 to be root.com/folder1/12 and it’s not working out at all.
Below is my htaccess code:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ index.php?id=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ index.php?id=$1
RewriteRule ^folder1/([a-zA-Z0-9_-]+)$ /folder1/index.php?id=$1
RewriteRule ^folder1/([a-zA-Z0-9_-]+)/$ /folder1/index.php?id=$1
Can you please let me know what I’m doing wrong with the folder1 rewriterule? Thanks a lot.
Also, how can I make an exception with the first rule so root.com/folder1 doesn’t get applied to the first rewrite rule?
You can add [L] at the end of your mod_rewrite commands, which means that this instruction is last. So if it have matched, no further instructions will work.
So using this you can first write more specific instructions, and later more general.