Reputation: 3215
I'm needing some help with mod rewriting. I have been looking online for the solution and I have seen code that claims to fix it but I either get a 404 error or the page is not css'ed.
This is what I'm trying to do:
http://example/dashboard/$page/$page_num
Now I'm in the dashboard directory so that's not a problem and I can get $page but whenever I try and get the $page_num I get the problem (because it's a optional number - it's only used in 3 of 20 so pages).
Here's my code I have now that's working to get http://example/dashboard/$page
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([^/]+)$ index.php?page=$1
RewriteRule ^([^/]+)/([^/.]+)$ index.php?page=$1&id=$2
The code in the last line is the code I have been trying for the $page_num I have tried it on top and bottom.
Upvotes: 1
Views: 94
Reputation: 49867
Can you try this:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^([^/]+)/?$ index.php?page=$1&page_num=1 [NC,L]
RewriteRule ^([^/]+)/([0-9]+)/?$ index.php?page=$1&page_num=$2 [NC,L]
I added the &id=1
in the page since by default you want to load the first page. The second parameters I only numbers so if you have other rules that requires letterers or numbers it wont conflict with this one.
Upvotes: 4