Forum Moderators: phranque

Message Too Old, No Replies

htaccess and wordpress again

just not getting it from prev threads

         

chewy

6:24 pm on Mar 1, 2011 (gmt 0)

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



it is clear that WP and htaccess require some fine tuning - my cut and paste tricks (and bits and pieces learned here over the years) don't seem to be working.

this does not work (and I would have never done it this way, but htaccess is all I can work with to fix the way the client wants it...)

redirect 301 http://www.example.com/ http://www.example.com/intro
redirect 301 http://www.example.com/ http://www.example.com/intro
redirect 301 http://www.example.com/contact.html http://www.example.com/contact/
redirect 301 http://www.example.com/index.html http://www.example.com/intro


# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

g1smd

11:20 pm on Mar 1, 2011 (gmt 0)

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



Do not mix Redirect and RewriteRule directives. Use RewriteRule for all of the rules. When used for redirects the RewriteRule requires the domain name included in the target and the [R=301,L] flags.

The canonical URL for the root of a site is
www.example.com/
with a trailing slash. Do not redirect this URL. Redirect TO this URL from named index pages.

DirectoryIndex index.php
allows the named index file to be displayed for a root URL request.

"Doesn't work" is too vague a clue to offer any other suggestions. What was it supposed to do? What did it do? How does that differ from what you wanted?

chewy

4:03 am on Mar 2, 2011 (gmt 0)

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



here is what is not working:

all queries to pages that do not exist are directed to a 404 page.

That's OK - however any calls to .html pages (left in th Google index) end up at the 404 instead of the specific new pages I want loaded.

normally i can do a permanent redirect, using the simple oldfilename newfilename structure but with Wordpress which seems to operate a bit differently than the simple sites I'm used to, I understand this requires a [R=301,L] which is going well over my head.

I can't find a good example to copy and tweak.

any clues appreciated.

oh, and the wordpress host is godaddy.

g1smd

8:37 am on Mar 2, 2011 (gmt 0)

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



RewriteRule ^old-path/old-file.ext http://www.example.com/new-path/new-file.ext [R=301,L]


There are more than 20 000 examples of redirects in this forum.

RewriteRule sees only the requested path. You need an additional preceding RewriteCond if you need to test the QUERY_STRING, HTTP_HOST, SERVER_PORT, or other parts of the THE_REQUEST.

chewy

3:32 pm on Mar 2, 2011 (gmt 0)

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



Thanks - Much obliged!

Most of the many thousand are confusing (to me) and there's enough at stake that I didn't want to experiment any further until I had a good solid lead.

Of course, I am cleaning up after someone was paid to do this - and they have even less of a clue than I do.

On top of that, I don't have a programming background (beyond a few hours of basic in high school in the 70's) so most regex reads like Klingon to me.

chewy

5:40 pm on Mar 2, 2011 (gmt 0)

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



oh - and as always...

Hats Off to you and the crew at WebmasterWorld!

g1smd

10:39 pm on Mar 2, 2011 (gmt 0)

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



RegEx is fairly simple, once you understand what the characters mean. There is no replacement for RTFM (where F=FAQ) every day for a week.

Once you understand what
! ^ ( ) . ? + * [^ ] { } \. \? $ %1 $1 
each signify, it becomes much more simple.

chewy

3:04 pm on Mar 3, 2011 (gmt 0)

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



so, wrong again!

how often I learn that I'm asking the wrong question.

turns out that somehow Wordpress dominates any redirection or rewrite code in htaccess.

so no amount of correct code makes any difference at all.

as a result, I would like to figure out WHAT is controlling these redirects.

header checking yields nothing useful
wordpress templates all seem standard
there are no whiz-bangy tools or extensions that apply.

host seems to think it isn't their responsibility.

but wait, there has to be more!

is there some WebmasterWorld-tastic tool that susses out this kind of mystery?

g1smd

7:50 pm on Mar 3, 2011 (gmt 0)

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



The order the code is in, within each individual .htaccess file, is key.

The order the htaccess files are processed in the root and in any folders also has an effect.

jdMorgan

10:05 pm on Mar 8, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Also, reading the mod_access documentation of the "Redirect" directive will soon reveal that

redirect 301 http://www.example.com/ http://www.example.com/intro

won't redirect anything, since the Redirect directive looks only at the URL-path-prefix. In this case, the URL-path should have been specified as

Redirect 301 / http://www.example.com/intro

But that would redirect all URLs in this domain after prepending ("intro"), and then redirect that page URL to add intro again and again -- looping forever. This is because the Redirect directive uses prefix-matching -- anything that starts with the specified URL-path is redirected to the new URL, with any part of the requested URL-path not specified in the Redirect directive appended to the new URL.

So, the path forward is to use RewriteRule instead of Redirect, and to put the rules in order: External redirects first, in order from most-specific URL-path and conditions to least, followed by all internal rewrites, again in order from most-specific to least. In this particular case, your WP code will go last.

Jim