Advanced URL rewriting

Hi guys! and girls. :)

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:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^domain.com

RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,L]

BEGIN WordPress

RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule . /index.php [L]

END WordPress

3 Replies

Something like:

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.

Mmm doesnt seem to have any affect when i add the line into my htacces.

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?

Hmmm, sucky answer - "but works for me"

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 http://www.domain.com

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 )

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct