krishnakhanna — 2012-09-19T14:02:41-04:00 — #1
I have site running and wish to convert the url
This requirement is opposite to the usual method to convert dynamic url to static url
How can this be achieved with mod rewrite rules
dklynn — 2012-09-20T07:14:56-04:00 — #2
I'm here to help members learn to create good mod_rewrite code (rather than offer free coding) so I'll ask you first to read the tutorial linked in my signature then make a valid attempt. Post your code and I'll be happy to critique it and offer additional pointers to get you where you want to go.
BTW, that's basically what WordPress's mod_rewrite does and they do a good job despite a few missteps that noobies might not be aware of. Look through this board for examples (and my critique).
krishnakhanna — 2012-09-20T08:33:36-04:00 — #3
Below is what I have written
RewriteRule ^index\.php\?data\=variable$ /variable [L]
And I wish to request the following from browser:
to get redirected to
However this doesn't redirect
cpradio — 2012-09-20T09:00:42-04:00 — #4
Your rewrite rule is backwards (or so it seems)
Since you want to capture /variable/ and redirect it to index.php?data=variable, you want to do the following
RewriteRule ^variable/? index.php?data=variable [L]
Then when you want to make it capture /*/ and redirect to index.php?data=*, you can do the following
RewriteRule ^([a-zA-Z0-9]+)/? index.php?data=$1 [L]
dklynn — 2012-09-22T07:24:37-04:00 — #5
Good reply except that I'd prefer to check that the request is not for a directory (or extensionless file) before your RewriteRule. That's important as not to do so could disable important functionality.
If you read the tutorial, you'd have known that your attempt was "backward" as cp noted. It's worthwhile to spend the time to read and understand the tutorial and look through the sample code (and explanations) at the end.
cpradio — 2012-09-22T20:48:13-04:00 — #6
Bah! :headbang: I knew that! I can't believe I forgot it. Next time I'll nail it!
dklynn — 2012-09-23T03:41:48-04:00 — #7
:tup: Not bad anyway!