Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2006-04-14 15:50:36

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

htaccess 301 redirect rule towards TLD

As I am illiterate with regular expressions at all, I’d like to ask the following question.
I am hosted at Textdrive, and I want all requests towards http://domain.com/everything redirected towards http://www.domain.com/everything, so as not to have double permlink locations.
Which is the rewrite rule, that I have to add to my htaccess file ?

Any help appreciated, regards


⌃ ⇧ < ⌃ ⇧ >

Offline

#2 2006-04-14 16:24:24

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

Re: htaccess 301 redirect rule towards TLD

Hi Marios
Would it be something like

<code>RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/everything/
RewriteCond %{HTTP_HOST} domain.com$
RewriteRule ^(.*)$ everything/$1 [L] </code>

I’m not certain but I think it would work


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

Offline

#3 2006-04-14 19:40:15

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: htaccess 301 redirect rule towards TLD

This is what I have now: <code># DirectoryIndex index.php index.html
  1. Options +FollowSymLinks
  2. RewriteBase /relative/web/path/

<IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^(.+) – [PT,L]

RewriteRule ^(.*) index.php </IfModule></code>

So , if I need the other rules:<code>
RewriteCond %{REQUEST_URI} !^/everything/
RewriteCond %{HTTP_HOST} domain.com$
RewriteRule ^(.*)$ everything/$1 [L]</code>, I just add these ?

I need to find the regular expression that matches any URL that could accur.
I’m not certain it would work, under everything I meant any URL that could occour.
I’ll see if I can adapt this.

regards,many thanks colak.


⌃ ⇧ < ⌃ ⇧ >

Offline

#4 2006-04-14 20:14:48

soulship
Member
From: Always Sunny Charleston
Registered: 2004-04-30
Posts: 669
Website

Re: htaccess 301 redirect rule towards TLD

I am using this on my txd(?joyent?) account. It seems to work fine for me.

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

Offline

#5 2006-04-14 21:01:14

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: htaccess 301 redirect rule towards TLD

@Jamie that doesn’t work, because any permlink request now that goes to http://example.com/permlink
goes to http://www.example.com/index.php, while it should go to httPp://www.example.com/permlink .

Now what I need is a rule that matches all the double permlink siblings locations,
when someone types without the www and sends them to it’s correspondent sibbling (www)
It’s basically a SEO thing, so you don’t confuse the search robots.

regards, marios

Last edited by marios (2006-04-14 21:04:37)


⌃ ⇧ < ⌃ ⇧ >

Offline

#6 2006-04-14 21:04:13

soulship
Member
From: Always Sunny Charleston
Registered: 2004-04-30
Posts: 669
Website

Re: htaccess 301 redirect rule towards TLD

Oh I see. That is a bit more tricky. Hmmm.

Offline

#7 2006-04-14 21:40:44

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: htaccess 301 redirect rule towards TLD

Hey Soulship thanks a lot for the help, I ‘m not sure though, it does the SEO trick.
I’ll do some research again.

regards, marios

Last edited by marios (2006-04-14 21:44:43)


⌃ ⇧ < ⌃ ⇧ >

Offline

#8 2006-04-15 02:59:55

Mary
Sock Enthusiast
Registered: 2004-06-27
Posts: 6,236

Re: htaccess 301 redirect rule towards TLD

I have my rules setup to do the opposite (I don’t want www), and it works great:

RewriteEngine on

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

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.*) index.php

Last edited by Mary (2013-01-24 17:15:22)

Offline

#9 2006-04-15 06:49:52

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: htaccess 301 redirect rule towards TLD

Ok, thanks Mary, that is exactly the rules I need, Now I think I’ll do it the other way around, and send any requeests that go http://example.com/ to www,

regards, marios


⌃ ⇧ < ⌃ ⇧ >

Offline

#10 2006-04-15 11:16:55

marios
Archived Plugin Author
Registered: 2005-03-12
Posts: 1,253

Re: htaccess 301 redirect rule towards TLD

Ok, to do the other way around (In case someone else needs this) you need to do this:
<code>

RewriteEngine on

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

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) – [PT,L]
RewriteRule ^(.*) index.php</code>

Note:There is a slight difference in the regular expression for the conditional rule.
<strong>CAUTION:</strong>This changes the URL of your backend as well, so keep that in mind.You loose your cookie,I think.

Thanks to all, regards

Last edited by marios (2006-04-15 12:10:01)


⌃ ⇧ < ⌃ ⇧ >

Offline

Board footer

Powered by FluxBB