Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2010-01-03 08:51:49

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

mod_rewrite htaccess help?

Wanted to ask if anyone could help me out with a bit of mod_rewrite code please. I need to make sure that http://www.mysite.com/paris is sent to http://paris.mysite.com

All the best for 2010.
Lee

Offline

#2 2010-01-03 16:10:13

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: mod_rewrite htaccess help?

This should work (in the root’s .htaccess):

Redirect permanent /paris http://paris.mysite.com

You can place it after the closing </IfModule> tag.

Offline

#3 2010-01-03 16:46:06

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: mod_rewrite htaccess help?

I’m guessing Lee wants to catch URLs such as http://www.mysite.com/paris/article-title as well?

Last edited by jsoo (2010-01-03 18:54:55)


Code is topiary

Offline

#4 2010-01-03 16:48:57

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: mod_rewrite htaccess help?

Hi guys, you’re right jsoo I need to catch everything. I’m hosting at joyent and subdomains like http://subdomain.site.com are also available at http:www.site.com/subdomain, I need to not let the latter happen if possible.

Cheers
Lee

Offline

#5 2010-01-03 17:05:48

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: mod_rewrite htaccess help?

jsoo wrote:

I’m guessing Lee wants to catch URLs such as http://www.mysite.com/paris/article-title as well?

As far as I know that’s what it does. Why don’t you just test it?

Last edited by els (2010-01-03 17:06:41)

Offline

#6 2010-01-03 18:54:40

jsoo
Plugin Author
From: NC, USA
Registered: 2004-11-15
Posts: 1,793
Website

Re: mod_rewrite htaccess help?

Els wrote:

As far as I know that’s what it does. Why don’t you just test it?

Sensible advice! Confirming that your solution is correct — my mistake.


Code is topiary

Offline

#7 2010-01-03 20:04:05

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,388
Website GitHub Mastodon Twitter

Re: mod_rewrite htaccess help?

This may also work:

RedirectMatch 301 http://www.mysite.com/paris(.*) http://paris.mysite.com/$1

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#8 2010-01-03 20:21:39

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: mod_rewrite htaccess help?

Thanks for all the help guy’s. Both bits of code work, but is one in any way preferable to the other?

Offline

#9 2010-01-03 20:48:27

ruud
Developer Emeritus
From: a galaxy far far away
Registered: 2006-06-04
Posts: 5,068
Website

Re: mod_rewrite htaccess help?

They are almost identical. I think the one Els posted is easier to read and understand for humans.

I do wonder what happens if you’d visit the following URLs:
  1. http://www.mysite.com/parisian
  2. http://www.mysite.com/paris/foo

Looking at the mod_rewrite rules, I’d suspect this would happen (not tested though)

Els
  1. http://paris.mysite.comian [bad]
  2. http://paris.mysite.com/foo
Colak
  1. http://paris.mysite.com/ian [bad]
  2. http://paris.mysite.com//foo [bad or ugly]

Offline

#10 2010-01-03 22:38:16

lee
Member
From: Normandy, France
Registered: 2004-06-17
Posts: 831

Re: mod_rewrite htaccess help?

Thanks for the help all, in the end I opted to create a real subdomain with it’s own virtual webserver which seems to work OK. Rudd’s questions and examples made me realise I was in over my head and needing a reliable, bullet proof solution I took the easy route.

Have a healthy and happy year…

Offline

#11 2010-01-29 20:00:56

jstubbs
Member
From: Hong Kong
Registered: 2004-12-13
Posts: 2,395
Website

Re: mod_rewrite htaccess help?

Need to redirect a site from mysite.com to newsite.com. Not an expert in .htaccess so appreciate any help with the appropriate directive.

How is this:

redirect 301 / http://www.newsite.com

Anyone have experience on whether this affects email delivered to the old domain in any way? Just wondering.

Offline

#12 2010-12-31 00:09:42

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: mod_rewrite htaccess help?

I’m trying to do something similar.

I want any call to domain.tld/yyyy (where “yyyy” is a 4-digit date like “2010”) to appear as yyyy.domain.tld in the browser address bar.

I already force dropping “www” by using…

RewriteCond %{HTTP_HOST} ^www\.domain\.tld [NC]
RewriteRule (.*) http://domain.tld/$1 [R=301,L]

So far so good.

But no matter what I try after that, I can’t get the subdomain to force to the front of the domain.

Here’s one of the more complicated examples I’ve tried…

RewriteCond %{HTTP_HOST} ^domain\.tld/([0-9]+)/([a-z-]+)\.html [NC]
RewriteRule (.*) %1.domain.tld/%2.html [NC]

This doesn’t break anything, but it doesn’t do what I want either. I.e., if I type “yyyy.domain.tld”, I’ll see yyyy.domain.tld in the address bar, and navigating around will give me yyyy.domain.tld/foo.html. Fine. But if also type “domain.tld/yyyy” I’ll see domain.tld/yyyy/, etc, which is not what I want to show people. It doesn’t redirect or mask or alias or whatever you call it.

Is it even possible to force one look over the other like that?

Offline

#13 2010-12-31 01:27:59

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: mod_rewrite htaccess help?

Hmm… this might be relevant in my case, mod_rewrite on (Joyent) virtual subdomains.

First slee… zzzzzz.

Edit: Looking at that now after some sleep, I don’t think that was the problem. Back to the drawing board.

Last edited by Destry (2010-12-31 10:48:56)

Offline

#14 2011-01-01 11:46:44

Destry
Member
From: Haut-Rhin
Registered: 2004-08-04
Posts: 4,912
Website

Re: mod_rewrite htaccess help?

With some quick help from the guys at stack overflow, I got the right rules, working great. No Joyent virtual directory issue at all…

RewriteCond %{HTTP_HOST} ^domain\.tld$
RewriteRule ^([0-9]+)/([a-z-]+)\.html$ http://$1.domain.tld/$2.html [NC,L,R=301]

Happy new year!

Offline

Board footer

Powered by FluxBB