[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

.htaccess redirect from static site to Wordpress

Posted on 2009-04-15
7
Medium Priority
?
728 Views
Last Modified: 2012-05-06
I'm trying to redirect pages from an old static site to new pages in WordPress. So, for example,

http://www.mysite.com/contact.htm

should redirect to:

http://www.mysite.com/contact

I'm using the following in the .htaccess file, but it's not working:

redirect 301 /mysite/contact.htm http://www.mysite.com/contact

0
Comment
Question by:carrboro
7 Comments
 
LVL 51

Expert Comment

by:Steve Bink
ID: 24154491
When you say "not working", what gives you that impression?  I mean, aside from not seeing the new page.  Are you receiving any error messages?  Have you examined the request/response conversation?
0
 
LVL 7

Expert Comment

by:mchkorg
ID: 24155371
Hi,
I would do it with Apache's URL Rewriting engine.

- be sure to have the rewrite_module enabled (via : a2enmod rewrite)
- in your site configuration (or local .htaccess), add something like :
        RewriteEngine On
        RewriteRule ^http://www.mysite.com/contact.htm http://www.mysite.com/contact

I hope this helps



0
 

Author Comment

by:carrboro
ID: 24157519
By not working I mean the old URLs are still resolving to the old, static HTML pages rather than the new WordPress pages.

I tried the rewrite above, but that is not working either. Here is what my current .htaccess file looks like. Note that I have WordPress in its own /blog directory and am using a page, rather than the blog, as my home page.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress
RewriteCond %{HTTP_HOST} ^hedgehog-fox.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.hedgehog-fox.com$
RewriteRule ^.*$ "http\:\/\/www\.jeffthomascobb\.com\/blog" [R=301,L]
0
Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

 
LVL 7

Expert Comment

by:mchkorg
ID: 24159390
No need to add RewretiEngine on as it's already done

Have you done several tests with my RewriteRule thing ? I think the I remember the sequence is important - you should check on apache2 official web site : http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html

=> did you try it right after the "RewriteEngine On" line ?
0
 
LVL 26

Expert Comment

by:souseran
ID: 24163736
Your 301 RewriteRule doesn't look right to me. I think it should be

RewriteRule ^(.*)$ http://www.jeffthomascobb.com/blog/$1 [R=301,L]

Also, I think you want an [NC] at the end of your last RewriteCond so that the rule takes effect regardless of the case in the browser address bar. Otherwise, only www.hedgehog-fox.com will be redirected. www.Hedgehog-Fox.com, etc. won't.
0
 

Author Comment

by:carrboro
ID: 24163909
None of the above is working. I really don't want to change the Rewrite rule as souseran suggests, as that Rewrite has been working fine. It was in place before the changes that led to this question.

I have tried the putting the Rewrite after Rewrite on, and that makes no difference. I have also checked to order.

I am not actually clear why Rewrite would be the correct approach in the first place, given that what I am trying to redirect is static HTML pages, whereas Rewrite - at least as I understand it - tends to apply when the pages to be redirected are dynamic. Regardless, it seems to me this should not be terribly complicated. Someone must know the right approach to this.
0
 

Accepted Solution

by:
carrboro earned 0 total points
ID: 24290012
I ended up figuring this out myself and implemented as a series of rewrites along the lines of:

RewriteCond %{HTTP_HOST} ^jeffthomascobb.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.jeffthomascobb.com$
RewriteRule ^contact\.htm$ "http\:\/\/www\.jeffthomascobb\.com\/contact\/" [R=301,L]

etc.

Works fine now
0

Featured Post

Veeam and MySQL: How to Perform Backup & Recovery

MySQL and the MariaDB variant are among the most used databases in Linux environments, and many critical applications support their data on them. Watch this recorded webinar to find out how Veeam Backup & Replication allows you to get consistent backups of MySQL databases.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…
The purpose of this video is to demonstrate how to set up basic WordPress SEO. This will be demonstrated using a Windows 8 PC. The plugin used will be WordPress SEO by Yoast. Go to your WordPress login page. This will look like the following: myw…
Suggested Courses
Course of the Month19 days, 18 hours left to enroll

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question