• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

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!
0
darkbluegr
Asked:
darkbluegr
  • 6
  • 6
1 Solution
 
HellmarkCommented:
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
 
darkbluegrAuthor Commented:
Thanks! and i dont have to indicate that /blog/article1 now corresponds to /article1 ?
0
 
HellmarkCommented:
Nope, the $1 part basically dumps the rest of the string (the article1 part) into the URL.
0
Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

 
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
 
HellmarkCommented:
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
 
HellmarkCommented:
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
 
HellmarkCommented:
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
 
HellmarkCommented:
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

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

  • 6
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now