Reputation: 37
I have been trying several variations to get my server to redirect - but all seem to fail. :(
This is my url:
"meaty-monster-bikes.zz-reviews.com/monster-bikes/p1c9.html"
Now the data I want to collect in variables is the portion after
"meaty-monster-bikes.zz-reviews.com/"
so in this case I want "monster-bikes" and "p1c9"
Then using the collected variables the server can redirect to:
"zz-reviews.com/index.php?p=1&c=9&k=monster-bikes"
I have thried this in my .htaccess file:
Options +SymLinksifOwnerMatch
RewriteEngine On
RewriteRule ^[\.0-9-a-z]+/([-a-z]+)/p([0-9]+)pg([0-9]+)\.html$ index.php?p=$2&c=$3&k=$1 [NC,QSA,L]
I also tried :
RewriteCond %{HTTP_HOST} ^[.+].zz-reviews.com/([-a-z]+)/[.+]$ [NC]
RewriteRule ^[\.0-9,:\/-a-z]+p([0-9]+)c([0-9]+)\.html$ index.php?p=$1&c=$2&k=%1 [NC,QSA,L]
As far as I can see, both should work, but neither do.
This is the webpage:
http://zz-reviews.com/index.php?p=1&c=9&k=monster-bikes
If you click on the Category "Monster Bikes"
You will see this url:
"http://meaty-monster-bikes.zz-reviews.com/monster-bikes/p1c9.html"
The htaccess does not properly redirect.
Can anyone see my mistake ?
Thanks .
.
Upvotes: 0
Views: 36
Reputation: 5253
RewriteRule ^([^./]+)/([a-z]+)(\d+)([a-z]+)(\d+)\.html$ index.php?$2=$3&$4=$5&k=$1 [L,NC]
This is the Rule you need - when you go to the url
meaty-monster-bikes.zz-reviews.com/monster-bikes/p1c9.html
You will redirect (behind the scenes) to this url
meaty-monster-bikes.zz-reviews.com/index.php?p=1&c=9&k=monster-bikes
Explaination:
^([^./]+)
- starts after the com the first arg ($1
) take all characters until /
- this will take the string "monster-bikes"
/
- the / character of the url
([a-z]+)
- follow by abc letter (you can change it if there are other strict) this will take "p" ($2
)
(\d+)
- follow by number - this will take "1" ($3
)
([a-z]+)
- follow by abc letter - this will take "c" ($4
)
(\d+)
- follow by number - this will take "9" ($5
)
\.html$
- ends with string ".html"
Redirect it to index.php with the assembled parameters:
index.php?$2=$3&$4=$5&k=$1
= index.php?p=1&c=9&k=monster-bikes
Upvotes: 1