Web Professionals use mod_rewrite to issue 301 and 302 Redirects for Search Engines. Sometimes you may not have mod_rewrite.c or you want an alternative redirect method. Using mod_alias RedirectMatch you can use REGEX in Redirect commands!
« PHP htaccess tips | .htaccess Tutorial Index | » mod_rewrite tips and tricks
SEO Search Engine Friendly Redirects without mod_rewrite
SEO 301 Redirect Single File
Redirect 301 /d/file.html /ddd/file.html
Redirect Home to new Domain
Redirect 301 / http://www.htaccesselite.com
301 Redirect multiple files
RedirectMatch 301 /blog(.*) /$1
Redirect Entire site to single file
Note: This is a 302 (temporary)redirect because its meant to point to a temporarily offline file.
RedirectMatch 302 ^/ /temporary-offline.html
Putting it all together
301 and 302 Redirects
Redirect 301 /security/rigging-the-dreamhost-site-of-the-month-contest.html http://www.askapache.com/dreamhost/rigging-the-dreamhost-site-of-the-month-contest.html Redirect 301 /htaccess/speed-up-the-apache-web-server-with-configuration-hacks.html http://www.askapache.com/htaccess/apache-web-server-speed-configuration-hacks.html Redirect 301 /2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html http://www.askapache.com/dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html Redirect 301 /2007/phpbb/sending-post-form-data-with-php-curl.html http://www.askapache.com/htaccess/sending-post-form-data-with-php-curl.html Redirect 301 /htaccess.txt http://z.askapache.com/uploads/p/htaccess.txt Redirect 301 /2007/webmaster/php-and-ajax-shell-console.html http://www.askapache.com/tools/php-and-ajax-shell-console.html Redirect 301 /2007/webmaster/custom-phpini-with-fastcgi-on-dreamhost.html http://www.askapache.com/dreamhost/custom-phpini-with-fastcgi-on-dreamhost.html Redirect 301 /seo/tailrankcom-robot.html http://www.askapache.com/seo/tailrank-robot.html Redirect 301 /instruct-search-engines-to-come-back-to-site-after-you-finish-working-on-it.html http://www.askapache.com/htaccess/503-service-temporarily-unavailable.html Redirect 301 /htaccess/instruct-search-engines-to-come-back-to-site-after-you-finish-working-on-it.html http://www.askapache.com/htaccess/503-service-temporarily-unavailable.html Redirect 301 /webmaster/lft-traceroute-tool.html http://www.askapache.com/tools/lft-traceroute-tool.html # 302 Temporary Redirect 302 /apachesearch/ http://google.com/coop/cse?cx=002660089121042511758%3Akk7rwc2gx0i
RedirectMatch with wildcards
RedirectMatch 301 ^/wp-content/uploads/p/(.*)$ http://z.askapache.com/p/$1 RedirectMatch 301 ^/(.*)apache-htaccess.html/2/(.*)$ http://www.askapache.com/htaccess/using-http-headers-with-htaccess.html$2 RedirectMatch 301 ^/(.*)apache-htaccess.html/3/(.*)$ http://www.askapache.com/htaccess/php-htaccess-tips-and-tricks.html$2 RedirectMatch 301 ^/(.*)apache-htaccess.html/4/(.*)$ http://www.askapache.com/htaccess/seo-search-engine-friendly-redirects-without-mod_rewrite.html$2 RedirectMatch 301 ^/(.*)apache-htaccess.html/5/(.*)$ http://www.askapache.com/htaccess/mod_rewrite-tips-and-tricks.html$2 RedirectMatch 301 ^/(.*)apache-htaccess.html/6/(.*)$ http://www.askapache.com/htaccess/speed-up-your-site-with-caching-and-cache-control.html$2 RedirectMatch 301 ^/(.*)apache-htaccess.html/7/(.*)$ http://www.askapache.com/htaccess/apache-authentication-in-htaccess.html$2 RedirectMatch 301 ^/(.*)apache-htaccess.html/8/(.*)$ http://www.askapache.com/htaccess/security-with-apache-htaccess.html$2 RedirectMatch 301 ^/(.*)apache-htaccess.html/9/(.*)$ http://www.askapache.com/htaccess/ssl-example-usage-in-htaccess.html$2 RedirectMatch 301 ^/(.*)apache-htaccess.html/10/#htaccess-glossary http://www.askapache.com/htaccess/htaccess-for-webmasters.html#htaccess-glossary RedirectMatch 301 ^/(.*)apache-htaccess.html/10/(.*)$ http://www.askapache.com/htaccess/apache-variable-fun-in-htaccess.html$2 RedirectMatch 301 ^/(.*)\.htm$ http://www.askapache.com/$1.html RedirectMatch 301 ^/200([0-9])/([^01])(.*)$ http://www.askapache.com/$2$3 RedirectMatch 301 ^/(.*)/htaccesselite-ultimate-htaccess-article.html(.*) http://www.askapache.com/htaccess/apache-htaccess.html RedirectMatch 301 ^/(.*)\.html/1/(.*) http://www.askapache.com/$1.html$2 RedirectMatch 301 ^/category/(.+)$ http://www.askapache.com/$1
Redirecting using the following directives is done using the module mod_alias. RedirectMatch, RedirectPermanent, RedirectTemp, Redirect
htaccess Guide Sections
- htaccess tricks for Webmasters
- HTTP Header control with htaccess
- PHP on Apache tips and tricks
- SEO Redirects without mod_rewrite
- mod_rewrite examples, tips, and tricks
- HTTP Caching and Site Speedups
- Authentication on Apache
- htaccess Security Tricks and Tips
- SSL tips and examples
- Variable Fun (mod_env) Section
- .htaccess Security with MOD_SECURITY
- SetEnvIf and SetEnvIfNoCase Examples
« PHP htaccess tips | .htaccess Tutorial Index | » mod_rewrite tips and tricks
Related Articles
10.25.07 at 1:45 pm
Hi,
I’m trying to figure out the syntax for an .htaccess line entry that would
perform the following redirection
mysite.com/level.itml/icOid/184 mysite.com/noticemykeywordI thought this would work :
Redirect 301 /level\.itml/icOid/184 http://www.mysite.com/noticemykeywordbut it doesn’t.
I’ll keep reading and experimenting, but I’d really appreciate any suggestions or tips.
Thanks,
11.01.07 at 11:04 pm
@ D K
12.17.07 at 1:48 pm
Hi,
I’m trying to 301 redirect a url that contains a question mark, but I can’t get it to view the ? literal. I’m assuming that’s the issue.
Here’s what I’ve tried, but hasn’t worked.
URL I want redirected -
http://www.mysite.com/foo/?section=pageAny ideas of what I’m doing wrong. Thanks!