djp1988 Posted August 28, 2009 Share Posted August 28, 2009 I have a url with which I am doing a rewrite, the page displays photos, and at request, I'm adding extra features, one of which is the possibility to search specific photos according to a key word, here is an example:www.mydomain.com/photo/france/=> shows a page with photos from franceI am letting people search for photos from france with an extra keyword, say "castle" so I thought I could just add for example:www.mydomain.com/photo/france/?photo=castleBut it doesn't seem I can add the extra GET variable like thisWhat can I do ? I would prefer to avoid doing more rewrites, so this result isn't really what I'm looking at: www.mydomain.com/photo/france/castle/This is only because I have another variable, the page number so I sometimes have:www.mydomain.com/photo/france/3/And it just gets more complicated if I add the extra key word to the url as part of the rewrite Link to comment Share on other sites More sharing options...
Ingolme Posted August 28, 2009 Share Posted August 28, 2009 I usually program my rewrites to accept a '?' and other variables at the end of the URL to add any possible variables I might want to add later.Something like this:^regular expression\??([^\?]*)$ Link to comment Share on other sites More sharing options...
boen_robot Posted August 28, 2009 Share Posted August 28, 2009 I like to have a single RewriteRule like this: RewriteRule ^([^\_].*)/ /index.php?uri=%{REQUEST_URI}&%{QUERY_STRING} So that every URL that doesn't start with "_" is mapped to a single PHP file, and if you want, you can still have a query string.You'll need to manually manage the rest of your URI though. With this system,www.mydomain.com/photo/france/?photo=castlewill be rewritten towww.mydomain.com/index.php?uri=photo/france/&photo=castleandwww.mydomain.com/photo/france/3/will be rewritten towww.mydomain.com/index.php?uri=photo/france/3/&Don't forget to prefix static resources with "_" though, so that for example, you can havewww.mydomain.com/_style.cssand/orwww.mydomain.com/_scripts/main.js"as is", and not being rewritten. Link to comment Share on other sites More sharing options...
djp1988 Posted August 28, 2009 Author Share Posted August 28, 2009 I usually program my rewrites to accept a '?' and other variables at the end of the URL to add any possible variables I might want to add later.Something like this:^regular expression\??([^\?]*)$I prefer this solution, it looks more suited to my problem, but I'm not sure how to implement it... my rewrite is:RewriteEngine onRewriteRule ^species/([^_/]*)_([^_/]*)/([0-9]+)$ /species/$1\_$2\/$3/ [R]RewriteRule ^species/([^_/]*)_([^_/]*)$ /species/$1\_$2\/ [R]RewriteRule ^species/([^_/]*)_([^_/]*)/([0-9]+)/$ /species.php?g=$1&s=$2&page=$3RewriteRule ^species/([^_/]*)_([^_/]*)/$ /species.php?g=$1&s=$2 So firstly i make sure there's a slash on the end, that's the first two lines, and then I call a species page with the 2 or 3 variables to show pictures of that animal (i was talking about countries before, but it's animals).My first attempt would be: RewriteEngine onRewriteRule ^species/([^_/]*)_([^_/]*)/([0-9]+)$ /species/$1\_$2\/$3/ [R]RewriteRule ^species/([^_/]*)_([^_/]*)$ /species/$1\_$2\/ [R]RewriteRule ^species/([^_/]*)_([^_/]*)/([0-9]+)/$ /species.php?g=$1&s=$2&page=$3RewriteRule ^species/([^_/]*)_([^_/]*)/([0-9]+)/\??([^\?]*)$ /species.php?g=$1&s=$2&page=$3&$4RewriteRule ^species/([^_/]*)_([^_/]*)/$ /species.php?g=$1&s=$2RewriteRule ^species/([^_/]*)_([^_/]*)/\??([^\?]*)$ /species.php?g=$1&s=$2&$3 My first attempt looks good but it doesn't seem to be working... Link to comment Share on other sites More sharing options...
Ingolme Posted August 28, 2009 Share Posted August 28, 2009 Add [QSA] at the end of your rewrite lines, Otherwise the rewrite won't even see anything beyond the '?'Example: RewriteRule ^species/([^_/]*)_([^_/]*)/([0-9]+)/$ /species.php?g=$1&s=$2&page=$3 [QSA] Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.