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!
darkbluegrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

HellmarkLinux Systems AdministratorCommented:
in your .htaccess file have the following
Options +FollowSymlinks
RewriteEngine on
RewriteOptions MaxRedirects=10
RewriteRule ^(.+)$ http://new_domain.com/$1 [R=301,NC]

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
darkbluegrAuthor Commented:
Thanks! and i dont have to indicate that /blog/article1 now corresponds to /article1 ?
0
HellmarkLinux Systems AdministratorCommented:
Nope, the $1 part basically dumps the rest of the string (the article1 part) into the URL.
0
Cloud Class® Course: Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

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

works like a charm

thanks!
0
darkbluegrAuthor Commented:
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 ?
0
HellmarkLinux Systems AdministratorCommented:
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

0
darkbluegrAuthor Commented:
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.
0
HellmarkLinux Systems AdministratorCommented:
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

0
HellmarkLinux Systems AdministratorCommented:
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/
0
HellmarkLinux Systems AdministratorCommented:
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

0
darkbluegrAuthor Commented:
thanks for the cleaned-up solution, confirmed it works perfectly!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Apache Web Server

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.