Back to this stuff again Just wondering if I wanted to extract 2 values from the URL e.g. Using the url domain.com/a/b/ typed into the browser I actually want it to call domain.com/x.php?var1=a&var2=b When I run my rewrite rule all I get is domain.com/x.php?var1=a/b/&var2= Any ideas how to split it up? My rewrite rule is;
Thanks piniyini but still geting a=$1/$2 hmmm should there be anything else in between ^(.*)/ and (.*)$ ?
Problem is the first .* is too "greedy". But the fix is simple as pie RewriteRule ^([^/]+)/(.*)$ /x.php?a=$1&b=$2 [L] Code (markup): The "([^/]+)" will match (one or more) characters, up till it encounters a forward slash.
If the script is in the same directory as the .htaccess file, take off the / in /x.php. The RewriteBase line covers that. Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^([^.]+)/([^.]+)/$ x.php?a=$1&b=$2 [L] domain.com/whatever/whatever/ (Take out the / before $ if you don't want the / at the end of the URL.)
Thanks guys. Piniyini has been giving me a bit of a guided tour of mod rewrites and I've not been doing things completely the right way round. Words like "no! bad no no " and "smack" come to mind. I was trully made to feel like the grasshopper. Thanks for your help Piniyini
Hehe ...just in case you haven't yet seen this, it's a pretty good resource to learn and copy practical techniques from: http://httpd.apache.org/docs/2.0/misc/rewriteguide.html
Thanks Willy. Just skimmed over that and it looks like a pretty good resource You guys have all been a lot of help with this stuff and I appreciate it. I suppose for you lot this query is pretty simple.
Now I have come across probably the simplest mod rewrite rules yet and cant seem to get it to work the way I want. What I want to do is turn domain.com/this-text into domain.com/page.php?a=this-text This is my code so you can tell me how wrong I was <IfModule mod_rewrite.c> Options +Indexes Options +FollowSymLinks RewriteEngine on RewriteBase / RewriteRule /(.*)$ page.php?a=$1 [L] </IfModule> Code (markup):
I'd do RewriteEngine On RewriteRule ^(.*)/?$ page.php?a=$1 Code (markup): Like I've said before I'm not an expert in this but can hack like the best of em till it works
I can usually hack them till they work as well but this rewrite stuff is really giving me a headache. Thanks dct. I'll give it a try.
I think my problem is that when it's rewriting it keeps on rewriting. What it seems to be doing is setting a to page.php so the URL is effectively www.domain.com/page.php?a=page.php instead of ?a=this-text Should I write a condition for page.php?
Once upon time there was mod rewrite and Weirfire, A wedding and 4 threads later, They all lived happily ever after. The End (or is it)
Options +Indexes Options +FollowSymlinks RewriteEngine on RewriteBase / RewriteRule ^([^.]+)$ get-section.php?rewrite=$1 [L]
*gulp* In mod_rewrite, I don't even know what a recurrence is!! I think any URL on the site would point to get-section.php?rewrite=ANYTHING So only if every URL on the site originally has get-section.php?rewrite= in it should that code be used! Adding a unique extionson can make it work if there are URLs you don't want changed.
The only reason I say is I've tried something similar to that before and I got get-section.php?rewrite=get-section.php Because the rewrite rule looks for anything at the start it keeps rewriting the URL once it's rewritten. This is the way I see it anyway and is the reason I was asking if you could do write a condition to stop it looping if the URL was the format of the rewritten URL.