Wordpress redirect author URL

Hello,

I am trying to redirect the author URL to the homepage.

So when you place ?author=1 or 2 or 3 etc. to the end of your URL (e.g http://www.myurlexample.com/?author=1 ) you are redirected to a URL which lists all the posts for that user ID. If permalinks are turned on this shows what the username for that ID is. Which means it could be possible to discover what the admin username is.

I have placed this in my htaccess but it doesn’t seem to work.

RewriteCond %{REQUEST_URI}  ^/$
RewriteCond %{QUERY_STRING} ^/?author=([0-9]*)
RewriteRule ^(.*)$ http://www.myurlexample.com/? [L,R=301]

I got this from http://wordpress.org/support/topic/author1-2-3-how-to-stop-it. The URL I am trying to redirect to is not the example one shown, I changed it here as to not reveal what I am working on currently (just in case anyone points that out).

htaccess is not something I am overly skilled at so if anyone could help out I’d appreciate it.

Thanks very much,
Jon

Hi Jon!

Basically, WP does its own thing within the modules it uses to create a webpage for the visitor. HOWEVER, let’s take a look at your code and see what can be done with it:

# BEFORE the other WP code !!!
RewriteCond %{REQUEST_URI}  ^/$ 
# Empty URI? Leave off the / for Apache 2.x but this is not an ideal situation
# In its place, I'd use a !-f (not minus f) with RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{QUERY_STRING} ^[COLOR="#FF0000"]/?[/COLOR]author=([0-9][COLOR="#EE82EE"]*[/COLOR])
# That will NEVER work!
# [COLOR="#FF0000"]First[/COLOR], the query string is everything AFTER the ?. Including the ? will simply prevent a match.
# [COLOR="#EE82EE"]Second[/COLOR], use + rather than * to guarantee at least one digit
RewriteRule ^(.*)$ http://www.myurlexample.com/? [L,R=301]
# Redirect EVERYTHING?!? Um, no! If you want to redirect ANYTHING, use .? (rather than "^(.*)$" )
# Then, why use an external redirection? Simply use ... whatever you're directing to for the author's article list.

I have “problems” with WP’s code (mostly pedantic in nature) but, if you’d like to learn more about mod_rewrite (it appears that you need to learn something about it - copying the code you posted with all its errors got you nowhere), have a look at the mod_rewrite tutorial linked in my signature. It’s been made into a SitePoint article but has been available for more than 5 years (and it’s been updated at my website) with kudos from MANY SitePoint members.

Regards,

DK

Hi DK,

Thanks for the reply. You are right I do need to learn about mod_rewrite. Wordpress is not the best framework but it’s the one most clients ask for. I’ll work my way through the tutorials you have. As I have little knowledge I rely on Googling the problem and I have found this causes more problems than it fixes.

Thanks again!
Jon

JP,

No problem. If you need any help, just come back here (or PM me directly).

Regards,

DK