Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-02-07 17:24:11

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

htaccess sitewide - redirect 301

We are thinking of moving the neme site currently in a’ subdirectory called main to the root.

Does anybody know an htaccess way where we can redirect all incoming traffic to the new urls.

The schema we are using is

www.domain.tld/main/article_id/title
and we wish to redirect it to
www.domain.tld/article_id/title


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

Offline

#2 2011-02-07 18:09:49

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: htaccess sitewide - redirect 301

Hi Yiannis

Could you try one of this two, on the .htaccess inside /main/ folder.

Redirect 301 /main/?(.*) /$1

In some servers, you will need to explicitly use the full URL on the destination, so the above would be:

Redirect 301 /main/?(.*) http://www.domain.com/$1

Or:

RewriteRule main/?(.*) $1 [R=301,L] 

Hope that works!


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#3 2011-02-07 18:23:56

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

Re: htaccess sitewide - redirect 301

Hi Julián,

There is a way! great! Thanks!

I will be uploading the new site by the end of the week and test your suggestions. I just wasn’t sure that there was a generic way so we couldn’t decide to get rid of the subfolder which through time became superfluous.

I’ll let you know here once the site is up.


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

Offline

#4 2011-02-07 18:27:01

merz1
Member
From: Hamburg
Registered: 2006-05-04
Posts: 994
Website

Re: htaccess sitewide - redirect 301

Hint: Apache rewrite guide (not being an .htaccess expert at all)

deleted

Last edited by merz1 (2011-02-07 18:33:09)


Get all online mentions of Textpattern via OPML subscription: TXP Info Sources: Textpattern RSS feeds as dynamic OPML

Offline

#5 2011-02-07 18:39:05

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: htaccess sitewide - redirect 301

Hi Julián,

There is a way! great! Thanks!

You are welcome.

BTW, there is no need to put the .htaccess in the /main/ folder, I don’t know why I suggested that. Of course, it would work there too, afaik.


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#6 2011-02-13 19:21:59

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

Re: htaccess sitewide - redirect 301

Hi Julián

Just to let you know that Redirect 301 /main/?(.*) http://www.domain.org/$1 seems to be working beautifully.


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

Offline

#7 2011-02-13 20:21:16

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: htaccess sitewide - redirect 301

Hi Yiannis,
great to know. I’ve tested it in neme.org and saw it works for permalinks, but no for /main/ or /main/some_section/.
Any ideas?


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#8 2011-02-14 07:10:32

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

Re: htaccess sitewide - redirect 301

Hi Julián, You are right!

added

RewriteEngine On
RewriteRule ^main/texts/ /texts/ [R=301,L]
RewriteRule ^main/arts_info/ /arts_info/  [R=301,L]
RewriteRule ^main/calls/ /calls/ [R=301,L]

Our texts db is very precious to us as it is linked by various universities.


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

Offline

#9 2011-02-14 15:08:26

jakob
Admin
From: Germany
Registered: 2005-01-20
Posts: 5,001
Website GitHub

Re: htaccess sitewide - redirect 301

Just for info, you should be able to combine your three rules into one:

RewriteRule ^main/(texts|arts_info|calls)/ /$1/ [R=301,L]

TXP Builders – finely-crafted code, design and txp

Offline

#10 2011-02-14 16:02:54

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

Re: htaccess sitewide - redirect 301

jakob wrote:

Just for info, you should be able to combine your three rules into one:

RewriteRule ^main/(texts|arts_info|calls)/ /$1/ [R=301,L]

This looked interesting! Tried

RewriteRule ^main/(texts|arts_info|calls|rss|?rss=1|atom|?atom=1)/ /$1/ [R=301,L]

but returns a 500 error


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

Offline

#11 2011-02-14 16:53:10

maniqui
Member
From: Buenos Aires, Argentina
Registered: 2004-10-10
Posts: 3,070
Website

Re: htaccess sitewide - redirect 301

Yiannis.
I don’t think you can test for query strings directly on the RewriteRule pattern. You will have to use a RewriteCond %{QUERY_STRING} to test for a query string.

Anyway, I think this is a One Redirect rule to rule them All:

RedirectMatch 301 ^/main/?(.+)$ http://www.neme.org/$1 

I think you could replace all the other lines just with that line. Would like to know…


La música ideas portará y siempre continuará

TXP Builders – finely-crafted code, design and txp

Offline

#12 2011-02-14 17:38:56

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

Re: htaccess sitewide - redirect 301

maniqui wrote:

Yiannis.
I don’t think you can test for query strings directly on the RewriteRule pattern. You will have to use a RewriteCond %{QUERY_STRING} to test for a query string.

Anyway, I think this is a One Redirect rule to rule them All:

RedirectMatch 301 ^/main/?(.+)$ http://www.neme.org/$1

I think you could replace all the other lines just with that line. Would like to know…

indeed! this is the holy grail of redirects!

Thanks sooo much Julián


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

Offline

Board footer

Powered by FluxBB