Reputation: 33
All I want to do is remove a section of my urls, i assume that this is the easiest way.
This is how my URLs currently look:
subdomain.domain.com/site/blog/?action=viewArticle&url=$postTile
I want to remove:
?action=viewArticle&url=
So that I end up with something like:
subdomain.domain.com/site/blog/$postTitle
I've tried the below, but I've had no joy:
RewriteEngine on
RewriteRule ^ subdomain.domain.com/site/bwc/(blog)/(.*)/$ /bwc/blog/?action=viewArticle&url=$2
Please help - I think I need to utilise MOD_REWRITE, but I'm not too sure how. I also need a solution that will allow the friendly URLs to be linked too - can .htaccess/apache do this?
Upvotes: 3
Views: 108
Reputation: 16055
RewriteRule ^site/bwc/blog/(.*?)/$ site/blog/?action=viewArticle&url=$1
But note that in this case your urls will always have to end with a /
for this to work
What the rewrite rule does is basically php's str_replace
on the URI. It will run the regular expression you provide on the request URI and replace it with the replacement you have also given. To have a better understanding you need to be good with Regular Expressions, that some say are a language all by themselves. (.*?)
is a capture group in regex. Capture groups can be accessed as $\d
in replacement strings where \d
will be the consecutive number of the capture group in the pattern.
Long story short if you send a request that matches the regex pattern it will grab it, do the replacements and send that to the server, instead of the address you entered.
Upvotes: 3