Forum Moderators: phranque

Message Too Old, No Replies

Logs incorrect URL

         

member22

10:46 am on Mar 14, 2014 (gmt 0)

10+ Year Member



I have seen some unwanted URL requests in my logs and I would like to
redirect them to the correct URL.

Incorrect URL:
http://www.example.com/type/subtype/product/index.php

Correct URL:
http://www.example.com/type/subtype/product.html


To redirect incorrect to the correct one, I thought of this:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.+index\.php\ HTTP/
RewriteRule ^(.*)/index\.php$ http://www.example.com/$1.html? [R=301,L]


I was going to put this after individual page redirects and just above
non-www to www redirect. Could anybody check if my syntax is correct,
please?

lucy24

12:05 pm on Mar 14, 2014 (gmt 0)

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



You don't need the part about "the request", since you're redirecting to an entirely different URL, not just away from a named index file. Is it a pattern? If so, it's

RewriteRule ^(list-of-exact-names-here|with-pipes-as-appropriate)/index\.php http://www.example.com/$1.html? [R=301,L]


The generic form goes
^(([^/]+/)+)index\.php

but at this point it's essential to know whether you also have directory index files that really are called "index.php". If you do, you obviously can't have a generic redirect or you'll inadvertently send those requests to the wrong place.

Is there any pattern to the wrong requests? For example, recurring filenames, or everything in a particular directory?

g1smd

1:52 pm on Mar 14, 2014 (gmt 0)

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



You could also redirect bare folder URL requests.