It's been a pretty long time since I had to rewrite urls with apache, can someone help me with this pretty simple task.
Situation:
I have an index php page that loads a specific page depending on a query string (in this example, the QS is "m=foo" where foo = the page I want to load.
So, to begin I added this rule:
Code:
RewriteRule ^(.*)$ index.php?m=$1 [NC,L]
Rewrites to /foo
Next up, one of the pages has a blog so I need a few more variables:
Code:
RewriteRule ^(.*)/(.*)$ index.php?m=blog&v=$2 [NC,L]
Rewrites to /blog/someCategoryOrBlogTitle
And support for pagination:
Code:
RewriteRule ^(.*)/page-(.*)$ index.php?m=blog&p=$2 [NC,L]
Rewrites to /blog/page-1 , etc.
And support for pagination if you have category filtering on:
Code:
RewriteRule ^(.*)/(.*)/page-(.*)$ index.php?m=blog&v=$2&p=$3 [NC,L]
Rewrites to /blog/someCategory/page-1 , etc.
The end result in the htaccess file:
Code:
RewriteRule ^(.*)/(.*)/page-(.*)$ index.php?m=blog&v=$2&p=$3 [NC,L]
RewriteRule ^(.*)/page-(.*)$ index.php?m=blog&p=$2 [NC,L]
RewriteRule ^(.*)/(.*)$ index.php?m=blog&v=$2 [NC,L]
RewriteRule ^(.*)$ index.php?m=$1 [NC,L]
Cool, everything works but I also have a photo page in addition to the blog.
I want to be able to goto /photos/galleryName instead of index.php?m=photos&v=galleryName but when I add this 2 things happen.
1. The photo gallery works but the blog does not (it redirects to the photo gallery).
2. The blog works but the photo gallery does not (it redirects to the blog).
#1 or #2 happens depending on the order I add the line in the htaccess file.
I've tried:
Code:
RewriteRule ^(.*)/(.*)/page-(.*)$ index.php?m=blog&v=$2&p=$3 [NC,L]
RewriteRule ^(.*)/page-(.*)$ index.php?m=blog&p=$2 [NC,L]
RewriteRule ^(.*)/(.*)$ index.php?m=blog&v=$2 [NC,L]
RewriteRule ^(.*)/(.*)$ index.php?m=photos&v=$2 [NC,L]
RewriteRule ^(.*)$ index.php?m=$1 [NC,L]
And:
Code:
RewriteRule ^(.*)/(.*)$ index.php?m=photos&v=$2 [NC,L]
RewriteRule ^(.*)/(.*)/page-(.*)$ index.php?m=blog&v=$2&p=$3 [NC,L]
RewriteRule ^(.*)/page-(.*)$ index.php?m=blog&p=$2 [NC,L]
RewriteRule ^(.*)/(.*)$ index.php?m=blog&v=$2 [NC,L]
RewriteRule ^(.*)$ index.php?m=$1 [NC,L]
Also tried using a different query string name instead of "v" for the photos but it's still broken.
Little help?
I also tried putting in QSA flags in nearly everyone as random guesses but no luck. I must be doing something ******ed but I don't know what.
Last edited by Shoe Lace; 02-02-2012 at 08:16 PM.