Sooner or later, you’re probably going to point an old webpage to a new one. If you’ve spent a bunch of time with search engine optimization (SEO), you can retain your work by redirecting the old URL to the new one, and letting search engines know its permanent. Here’s how you can do that with Apache in Linux.
- Enable mod_rewrite if it hasn’t been already. Open up a terminal.
See which mods are enabled:
# apache2ctl -M
# a2enmod rewrite
# /etc/init.d/apache2 restart
- See which mods are enabled:
- Add redirection rules to a .htaccess file in the root of your site
Open .htaccess in a text editor. I prefer nano.
# nano .htaccess
Add the following to enable the rewrite engine for the site:
Add a rule to redirect a page permanently (301 means the redirect is permanent).
The following example redirects alextafoya.com/about/contactme.html to alextafoya.com/contact.php
Redirect 301 /about/contactme.html http://www.alextafoya.com/contact.php
- Open .htaccess in a text editor. I prefer nano.