Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#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
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
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
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
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:- http://www.mysite.com/parisian
- http://www.mysite.com/paris/foo
Looking at the mod_rewrite rules, I’d suspect this would happen (not tested though)
Els- http://paris.mysite.comian [bad]
- http://paris.mysite.com/foo
- http://paris.mysite.com/ian [bad]
- 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
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
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