Forum Moderators: phranque

Message Too Old, No Replies

htaccess - 301 redirection and WP SEO URLs don't work

         

krneki

1:02 pm on Oct 8, 2015 (gmt 0)

10+ Year Member



I've already searched thoroughly for tutorials on how to configure .htaccess but I just can't get it work properly no matter what I try. Hopefully you will be able to help me out, let me explain the current situation. There are already several 301 and other redirections in htaccess files, so let me simplify it and if it still won't work, I'll post full .htaccess files for a more detailed description.

Folder of old HTML website: public_html/old
Folder of new Wordpress based website (Site Address is set to www.example.com): public_html/new

As of now, new Wordpress website works fine if one opens www.example.com or www.example.com/new. However, the old website is still accessible via www.example.com/old, so I would like to redirect it to the new website. To put it in other words, I would like to permanently redirect absolutely everything from www.example.com/old as well as subfolders to the new website.

Could anyone please write me down which rules should I use in .htaccess and in which folder should I put it?



The second problem is about new Wordpress website. Everything works fine except when I try to use SEO URL's in http://example.com/sample-post/ format. In that case www.example.com will open fine, however I get the followiong 404 error for all subpages (e.g. www.example.com/news etc.)

"Not Found
The requested URL /index.php was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request."

Here's .htaccess from WP folder (public_html/new):
RewriteEngine On
DirectoryIndex index.php
RewriteBase /new
RewriteRule ^index\.php$ - [L]

# add a trailing slash to /wp-admin
RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^ - [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) $2 [L]
RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
RewriteRule . index.php [L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /new/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /new/index.php [L]
</IfModule>

# END WordPress


Thanks a lot for help!

[edited by: engine at 7:04 pm (utc) on Oct 8, 2015]
[edit reason] Please use example.com [/edit]

lucy24

8:26 pm on Oct 8, 2015 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



As of now, new Wordpress website works fine if one opens www.example.com or www.example.com/new. However, the old website is still accessible via www.example.com/old, so I would like to redirect it to the new website.

Are you talking about physical directories, about URLs, or both?

Do requests for
example.com/
and
example.com/new/
lead to the same content, or different content?

Are /new/ and /old/ directories located parallel to each other? (That is, each of them side by side inside the /example.com/ directory.) If so, you can make redirects until the cows come home and it will never have any effect, because requests for /old/ will never see the /new/ htaccess file.

not2easy

9:10 pm on Oct 8, 2015 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



At first glance, it looks like a problem of trying to resolve WP configuration issues with htaccess which won't work. This:
(Site Address is set to www.example.com)
tells you why it won't go past the default (index.php)
It is possible to place your WP install in a subfolder and have it appear to be installed in the root. There are lots of WP tutorials on how to do that. If the admin Settings tell WP that it is in the root directory as shown in the quote above, then that is where it is no matter what you tell it from an external htaccess file. If you want to move it to a different folder than where it was you should review the Settings in WP and the wp-config.php file. You should never edit the lines in htaccess between
# BEGIN WordPress
<IfModule mod_rewrite.c>
and
# END WordPress
because WP will create (and/or overwrite) its own snippet in your htaccess file.

Instead, follow the WP instructions for moving your site. Look at the htaccess that WP put in the folder where it currently is (/old/) and use that to help you see what you need in the /new/ folder. WP only listens to its internal settings and configuration. Those setting need to reflect the new conditions, including the configurations for the sql database name and username. Both installs can't have the same settings and configuration files.

If I've misunderstood something in the original question I apologize, but my response is because that is what it looks like from what I see.