Forum Moderators: phranque

Message Too Old, No Replies

Redirect to a subdomain, but keep old permalinks

Need WP to co-exist with previous CMS pages

         

CerpinTraxt

3:59 pm on Apr 28, 2009 (gmt 0)

10+ Year Member



I have a blog with a custom "home-made" CMS on a domain www.domain.com. I want to upgrade it to Wordpress and keep the old permalinks, so I've set up the Wordpress installation on a subdomain [domain.com...] and thought I could easily redirect users from www.domain.com to www.domain.com/blog.

I can do that by 301 redirect in .htaccess file, but the old permalinks (www.domain.com/permalink/post-title) get messed up.

How can I make exceptions for those old permalinks. I want the old posts to still be readable and findable (on the old page).

Here is my .htaccess

Options +FollowSymLinks
RewriteEngine on

RewriteRule ^(novice)/
(zabava¦glasba¦filmi¦serije¦umetnost¦dogodki¦blodnje¦tehnologija¦druzba¦video¦igre¦politika¦narava¦fotografija¦internet)/([0-9]*)/ index.php?modul=$1&kategorija=$2&stran=$3

RewriteRule ^(novice)/
(zabava¦glasba¦filmi¦serije¦umetnost¦dogodki¦blodnje¦tehnologija¦druzba¦video¦igre¦politika¦narava¦fotografija¦internet)/ index.php?modul=$1&kategorija=$2

RewriteRule ^(novice)/([0-9]*)/ index.php?modul=$1&stran=$2
RewriteRule ^(novice)/ index.php?modul=$1

RewriteRule ^(arhiv)/([0-9]*)/([0-9]*)/ index.php?modul=$1leto=$2&mesec=$3
RewriteRule ^(arhiv)/ index.php?modul=$1

RewriteRule ^(permalink)/([0-9]*)/(.*)/ index.php?modul=$1newsid=$2&naslov=$3

RewriteRule ^(predlagaj)/(poslji)/ index.php?modul=$1poslji=$2
RewriteRule ^(predlagaj).html index.php?modul=$1

ErrorDocument 404 /index.php?modul=404

What do you recommend I should do?

Thank you so much for your help.

jdMorgan

4:07 pm on Apr 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It would be very helpful if you showed us the 301-redirect code you tried to use, and then describe exactly what happens when you type in an "old" permalink, and tell us "What is wrong with that," since we are not familiar with either your past or current site configuration.

Also, note that from your description, you installed WP in a subdirectory, not a subdomain.

Jim

CerpinTraxt

4:28 pm on Apr 28, 2009 (gmt 0)

10+ Year Member



Right, sry - subdirectory.

If I use

Redirect 301 / [domain.com...]

I get an infinte loop.

So I use

Redirect 301 /index.php [domain.com...]

And that seems to work, but it messes my old permalinks.

For instance:
[domain.com...]

becomes:

[domain.com...]

I have also tried with this

RewriteRule (.*) [domain.com...] [R=301,L]

But the result is the same.

jdMorgan

6:29 pm on Apr 28, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do not mix mod_alias (Redirect 301) and mod_rewrite (RewriteRule) directives, as you cannot be sure what order they will be executed in -- Apache directive processing is per-module and determined by the server configuration; directives are not processed in the line sequence order of your .htaccess code. Instead, each Apache module is invoked in turn, scans your .htaccess file, and executes only the directives that it recognizes.

As an example of potential problems, if your Redirect executes after your internal rewrite(s), then the internally-rewritten script filepaths will be exposed to the client (browser or search engine robot). Also, if you change servers (or get "upgraded" by your host) the relative order of processing of mod_alias and mod_rewrite may change, breaking your site.

As such, if you use mod_rewrite for any rewrites or redirects, it's a good idea to use it for all rewrites and redirects.

The most likely problem you're seeing is that either DirectoryIndex or the code installed by WP in /blog/.htaccess is interfering with your desired redirect. A likely solution is posted in this recent thread [webmasterworld.com].

You will probably want your RewriteRule and RewriteCond to handle requests both for "/" and for "index.php". To do that, the form of the subpattern will be "(index\.php)?" so that it matches either "index.php" or blank.

Note that all RewriteRules should end with an [L] flag, unless you know the reason that you don't want to use it in a particular case.

Jim