Link to home
Start Free TrialLog in
Avatar of darkbluegr
darkbluegr

asked on

redirect with htaccess

Hi, i had an old blog at www.domain.com/blog

now i moved to a new wordpress theme, and it doesnt have the /blog/ prefix for my blog posts (it combines all pages with posts in the main /)

so for all articles that im ranking, like www.domain.com/blog/article1 , i would like to point them to www.domain.com/article1 (omit the /blog)

how can i do that with .htaccess in a search-engine-friendly way? (301 redirect)

also, i would like all content that was indexed under my old /html directory (that is still coming up in search results) to redirect to my main url (/index.php) when people click on old search results.

thank you!
ASKER CERTIFIED SOLUTION
Avatar of Keith Brown
Keith Brown
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of darkbluegr
darkbluegr

ASKER

Thanks! and i dont have to indicate that /blog/article1 now corresponds to /article1 ?
Nope, the $1 part basically dumps the rest of the string (the article1 part) into the URL.
Thank you -- and do i add it before or after my existing .htaccess (the stock one from WP 3.2)



# 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
disregard -- i figured that i had to add what you sent me in /blog/.htaccess.

works like a charm

thanks!
quick one --

i had another subdirectory that had static html files

it was /static

how do i instruct this to go to the homepage at www.domain.com ?
is that from the root of your directory? I'd have your /blog/ folder still, and put that in its own .htaccess folder in the blog directory.

Another way to do it is add this into your existing one at the root, after the "# END WordPress" bit

//301 Redirect Entire Directory
RedirectMatch 301 domain.com/blog/(.*) domain.com//$1

Open in new window

perfect -- thank you.

only small glitch is that if someone had bookmarked /blog , they would be taken to an empty page now.. because i created the "blog" directory in order to add my .htaccess in.
On second thought, this may be more clean for you.

# 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]
RedirectMatch 301 ./blog/(.*) domain.com/$1
</IfModule>

# END WordPress

Open in new window

The above "cleaned" up example, you put in to your .htaccess in your webroot

And if they bookmarked domain.com/blog/ they should be directed to domain.com/
Also, as far as the static directory, adding another line akin to what was shown for blog would redirect that as well.

# 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]
RedirectMatch 301 ./blog/(.*) domain.com/$1
RedirectMatch 301 ./static/(.*) domain.com/
</IfModule>

# END WordPress

Open in new window

thanks for the cleaned-up solution, confirmed it works perfectly!