Advanced URL rewriting
First post here, ive been googling like mad and decided to go out and ask for help. I've hit a wall up here and whas hoping people here could help and point me in the right direction.
I've got a website wich needs some advanced url rewriting. Perhaps the thing i want to archieve isn't possible, but i doubt that.
I have a site wich is powered by wordpress with prety url rewrites. What i want to archieve is to look at the url and see if it has mydomain.com/products/productname" and then rewrite those pages to "productname.mydomain.com"
Is this possible with mod rewrite? Note that the url's are already being rewritten using:
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^(.*)$
BEGIN WordPress
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
END WordPress
3 Replies
RewriteMap upper2lower int:tolower
Rewriterule ^/products/(.*) http://${upper2lower:$1}.domain.com [R=301,L]
?
Checked on my server and works … the upper2lower just keeps things tidy lowercase.
Check here
http://tools.web-max.ca/requestinfo.php
with
stayau.com/product/yerrrrrrrr
stayau.com/product/BLING
However, if u have PHP access, I'd tend to rewrite to a PHP file which can then check if the product exists, and do the 302 from there via a header() command.
I'm not to good with rewrites and editing htacces. might just be doing something wrong. Could it be because of the default wordpress rules?
Should be at the start ( after "RewriteEngine On" )
Also, if I get this right from ur htaccess you check to see if the domain doesn't start with domain.com and then [301] to
So if the line isn't at the start, it will probably work, then come back in, see that it doesn't being with domain.com and redirect it back.
Which means you also need to remove
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,L]
( Unless you are going to a seperate virtual host )