.htaccess problem

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hello, I am hoping that someone can take a look at my htaccess file. I
have had some bad canonical problems and google has cached a load of my
pages with and without the /

I found the problem and corrected it but in my search to find the
problem there were modifications to the .htaccess The redirects seem to
work, visually at least (it redirects me to url/ from url without / but
not sure if that means it redirects the google bots etc).

There are loads more URL's but these are gist of it. Here's what I have:

#redirects from old site
redirect 301 /blog/ /about-us/blog/

RedirectMatch 301 ^/some-stuff(.*) http://www.example.com/more-stuff /

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

# END WordPress

Any help is welcome. My site is getting in a real mess

Re: .htaccess problem


Quoted text here. Click to load it

Hi Jez (you could've asked this in the forum ;-) )

If it's visually, and you see it still with JavaScript off you can be
sure it's an external redirect, i.e. the web server sends a response
that asks the browser/bot to fetch a different URL.

If you want to be 100% sure install the Live HTTP Headers Add On in
Firefox. You should see your browser request a page and getting a 301
back with the URL it actually should fetch, and then fetch that URL and
getting a 200 back (or a 302 Not Modified if the page is cached).

Quoted text here. Click to load it

Redirect, RedirectMatch, and RedirectPermanent are all in mod_alias (not
in mod_rewrite). This is just a FYI. Documentation is at:
http://httpd.apache.org/docs/current/mod/mod_alias.html

Note that instead of 301 you can also write permanent. Maybe easier to
remember?

Redirect permanent /blog/ /about-us/blog/

or:

RedirectPermanent /blog/ /about-us/blog/

Also, (another FYI, not relevant here) some time ago there was a
discussion here about a blog with pages gone (and returning 404s). If
some part of your site is GONE, return 410 (gone), not 404. E.g.

Redirect gone /my-old-index.html
RedirectMatch gone /my-old-blog

404 means not found, but there is no indication if this is temporary or
permanent. If you want to say: this is gone, and won't come back, return
410 (gone).

But (IMO) best is to redirect (permanent) to a best match. There is
already too much 404 shit on the Internet.

Quoted text here. Click to load it

something.*

and

something(.*)

are equivalent to:

something

if you do nothing with the stuff that's captured [1]. I.e.

RedirectMatch 301 ^/some-stuff(.*) http://www.example.com/more-stuff /

Is the same as:

RedirectMatch 301 ^/some-stuff http://www.example.com/more-stuff /

But maybe you mean:

RedirectMatch 301 ^/some-stuff(.*) http://www.example.com/more-stuff $1

Note that here you can also write 301 as 'permanent' (without the quotes).

I am somewhat sure that the hostname is not required (same with
Redirect), so I guess this could be written as:

RedirectMatch permanent  ^/some-stuff(.*) /more-stuff$1

If you want also /some-stuff/foo  to go to /more-stuff/foo

If for one reason or another you must include the hostname of the site,
use %


[1] Likewise:

    ^.*foo

is identical to:

  
   foo

And if you don't do anything with the captured data:

  ^(.*)foo

is also identical to:

  foo

Don't capture if you don't do anything with the data. It's confusing, if
I see:

  ^bar(.*)$   foo

I wonder if the author forgot $1 or doesn't mean that the above is
equivalent to

  ^bar        foo

To summarize:

.* directly after  ^ makes the ^ pointless: it reads as "the very start,
   but 0 or more characters can follow.
.* directly before $ makes the $ pointless: it reads as: "the very end,
   but 0 or more characters can be before it.

Of course if you capture the match /and/ use the match on the RHS they
are not pointless. (Or if you want to test the delay pointless things
cause in Apache).

--
John Bokma                                                               j3b

Blog: http://johnbokma.com/        Perl Consultancy: http://castleamber.com/
Perl for books:    http://johnbokma.com/perl/help-in-exchange-for-books.html

Re: .htaccess problem

On 21/06/2012 15:48, John Bokma wrote:
Quoted text here. Click to load it

Cheers John. I will post the whole thing in the forum. I have tied
myself in knots with this and got myself totally confused.


Re: .htaccess problem


Quoted text here. Click to load it

The whole redirect thing is complicated. I often have to check the
documentation as well.

--
John Bokma                                                               j3b

Blog: http://johnbokma.com/        Perl Consultancy: http://castleamber.com/
Perl for books:    http://johnbokma.com/perl/help-in-exchange-for-books.html

Site Timeline