Textpattern CMS support forum
You are not logged in. Register | Login | Help
- Topics: Active | Unanswered
#1 2008-03-30 19:28:08
- azw
- Member
- Registered: 2007-01-29
- Posts: 279
Moving site to Txp. How do I use redirect or rewrite with Txp?
Hello,
I’m moving an old site to Txp. I’ve got two related questions
First, I have the old pages on the main domain that need to be sent to the new versions, often with different names.
http://www.domain.com/oldpage.html >> http://www.domain.com/newpage.html
Second, I had a subdomain that I’m no longer using. All of those articles are going to a new folder in Txp’s site.
http://en.domain.com/page.html >> http://www.domain.com/en/newpage.html
I’ve tried a number of ways of using redirect and mod rewrite on the old subdomain with no success. I can get any request on the subdomain to be sent to the main domain, but so it only send visitors to the en folder’s index page.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^en.domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.en.domain.com$
RewriteRule ^(.*)$ http://www.domain.com/en/ [R=301,L]
Offline
#2 2008-03-31 07:50:04
- azw
- Member
- Registered: 2007-01-29
- Posts: 279
Re: Moving site to Txp. How do I use redirect or rewrite with Txp?
I’ve finally had success, so I’ll document here what I did in case it might help others later.
I’m running the MLP (multiple language pack), so that’s why en (English) and es (Spanish) appear in the new site as directories.
The code I used in the .htaccess of the old subdomain, was like this:
Options +FollowSymLinks +Includes -Indexes
redirect 301 /page.html http://www.domain.com/en/new-directory
redirect 301 /directory http://www.domain.com/en/new-directory
redirect 301 /index.html http://www.domain.com/en
ErrorDocument 500 http://www.domain.com/en/500
That’s a page on the second line, a directory in the third line, and the subdomain’s index page on the fourth line. All of the code was redirects for individual pages or individual directories.
The last line sends the visitor to the main domain’s error page if there’s an missing page (404, page not found) error on the subdomain.
In my case, all of the old individual pages are now addressed as folders in the new site because they are static pages in their own sections.
If you rename any pages, you won’t be able to simplify the second line like this:
redirect 301 / http://www.domain.com/en
That’s because it will match any page with “/”. Then it’ll add the page address after “http://www.domain.com/en”. But that simple line might work if it’s the only redirect you use. (I haven’t tested it in that situation.)
The links in my sites are always for the directory, and I don’t usually include the actual index file name (like index.html) in the links. But in the .htaccess file, it seems you have to specify the file name or the rule would be applied to other pages in the subdomain.
—————
In the main domain I used something like this:
#DirectoryIndex index.php index.html
Options +FollowSymLinks
Options -Indexes
Redirect 301 /directory http://www.domain.com/es/new-directory
Redirect 301 /page.html http://www.domain.com/es/new-directory
# the rest is the standard Txp .htaccess file
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /relative/web/path/
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+) - [PT,L]
RewriteRule ^(.*) index.php
RewriteCond %{HTTP:Authorization} !^$
RewriteRule .* - [E=REMOTE_USER:%{HTTP:Authorization}]
</IfModule>
#php_value register_globals 0
I didn’t include an index page redirect in the main domain because it turned requests for some pages in the old subdomain into requests for documents in the /es directory.
If you get errors when you’re developing your .htaccess file, you may get errors even on pages for which the redirects are okay but other lines in the code may be bad. In a case like that, comment out as many lines as necessary with the # character to see where the problem is. I found it easier to test with one page at a time until I had the schema working well.
If you use a “/” at the end of the redirect, like this:
redirect 301 /index.html http://www.domain.com/en/
that will sometimes result in multiple //s in the URL. So you probably won’t want to end your redirects with a “/”.
It’s really important to test your redirects and to watch your visitor log files for 404 (page not found) errors.
HTH
Last edited by azw (2008-04-02 18:53:58)
Offline
#3 2008-04-04 21:48:39
- azw
- Member
- Registered: 2007-01-29
- Posts: 279
Re: Moving site to Txp. How do I use redirect or rewrite with Txp?
Another update
I have had some problems with the redirects, probably related to the MLP extension for multilingual sites.
As I understand it, the MLP uses “language markers” ( for example: Spanish = /es, English = /en ) in the URL, but they are not really directories. MLP takes them out when it processes the requested page, but uses them to figure out which language’s version to display.
I’ve been getting 404 (page not found) errors, especially from Alexa and Googlebot. It appears that they are indexing my pages without putting the language marker in the URL, like:
http://main-domain.com/new-section-name/rendition-name
Supposedly, it shouldn’t matter if those language markers appear in the URL, especially since most of the language version have different names based on the title of each “rendition” (the language version of a page).
As a result, I’ve had to add a bunch more redirects for the English and Spanish pages, like this:
Redirect 301 /new-section-name/new-rendition-name
http://www.main-domain.com/es/new-section-name
(That’s all on one line.)
If the section has more than one article, I add the new-article-name to the second part of the redirect. Otherwise, I use just the section in the URL (as if it were a folder).
This has fixed most of the problems, but I’ve never had to have so many redirects. And I’ve got a huge, ugly .htaccess file as a result.
Am I doing something wrong? There must be a problem in MLP.
Offline