Skip to content

Instantly share code, notes, and snippets.

@ScottPhillips
Created February 2, 2012 04:30
Embed
What would you like to do?
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
#Redirect a sub folder to another site
Redirect 301 /subfolder http://www.domain.com/
#This will redirect any file with the .html extension to use the same filename but use the .php extension instead.
RedirectMatch 301 (.*)\.html$ http://www.domain.com$1.php
##
#You can also perform 301 redirects using rewriting via .htaccess.
##
#Redirect from old domain to new domain
RewriteEngine on
RewriteBase /
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]
#Redirect to www location
RewriteEngine on
RewriteBase /
rewritecond %{http_host} ^domain.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
#Redirect to www location with subdirectory
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/directory/index.html [R=301,NC]
#Redirect from old domain to new domain with full path and query string:
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^(.*) http://www.newdomain.com%{REQUEST_URI} [R=302,NC]
#Redirect from old domain with subdirectory to new domain w/o subdirectory including full path and query string:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/subdirname/(.*)$
RewriteRule ^(.*) http://www.katcode.com/%1 [R=302,NC]
Rewrite and redirect URLs with query parameters (files placed in root directory)
Original URL:
http://www.example.com/index.php?id=1
Desired destination URL:
http://www.example.com/path-to-new-location/
.htaccess syntax:
RewriteEngine on
RewriteCond %{QUERY_STRING} id=1
RewriteRule ^index\.php$ /path-to-new-location/? [L,R=301]
Redirect URLs with query parameters (files placed in subdirectory)
Original URL:
http://www.example.com/sub-dir/index.php?id=1
Desired destination URL:
http://www.example.com/path-to-new-location/
.htaccess syntax:
RewriteEngine on
RewriteCond %{QUERY_STRING} id=1
RewriteRule ^sub-dir/index\.php$ /path-to-new-location/? [L,R=301]
Redirect one clean URL to a new clean URL
Original URL:
http://www.example.com/old-page/
Desired destination URL:
http://www.example.com/new-page/
.htaccess syntax:
RewriteEngine On
RewriteRule ^old-page/?$ $1/new-page$2 [R=301,L]
Rewrite and redirect URLs with query parameter to directory based structure, retaining query string in URL root level
Original URL:
http://www.example.com/index.php?id=100
Desired destination URL:
http://www.example.com/100/
.htaccess syntax:
RewriteEngine On
RewriteRule ^([^/d]+)/?$ index.php?id=$1 [QSA]
Rewrite URLs with query parameter to directory based structure, retaining query string parameter in URL subdirectory
Original URL:
http://www.example.com/index.php?category=fish
Desired destination URL:
http://www.example.com/category/fish/
.htaccess syntax:
RewriteEngine On
RewriteRule ^/?category/([^/d]+)/?$ index.php?category=$1 [L,QSA]
Domain change – redirect all incoming request from old to new domain (retain path)
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example-old\.com$ [NC]
RewriteRule ^(.*)$ http://www.example-new.com/$1 [R=301,L]
If you do not want to pass the path in the request to the new domain, change the last row to:
RewriteRule ^(.*)$ http://www.example-new.com/ [R=301,L]
#From blog.oldsite.com -> www.somewhere.com/blog/
retains path and query, and eliminates xtra blog path if domain is blog.oldsite.com/blog/
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_URI}/ blog
RewriteRule ^(.*) http://www.somewhere.com/%{REQUEST_URI} [R=302,NC]
RewriteRule ^(.*) http://www.somewhere.com/blog/%{REQUEST_URI} [R=302,NC]
@apkzarcom
Copy link

Thank you for this guide information, now I can redetect site https://apkzar.com/ without any plugins, Thanks sir.
HOPE YOU HELP

@apkzarcom
Copy link

Thank you for this guide information, now I can redetect site https://apkyolo.com/ without any plugins, Thanks sir.

@apkzarcom
Copy link

now I can redetect site https://instamody.com/ without any plugins, Thanks sir.

@apkzarcom
Copy link

now I can redetect site https://apkrog.com/ without any plugins, Thanks sir.

@apkzarcom
Copy link

now I can site https://apkzar.co/ without any plugins, Thanks sir.

@apkzarcom
Copy link

hello this will help youmore https://nxtvillain.com

@trucaller12
This comment was marked as spam.
@marioaprea
Copy link

I would like to change document root path for sites installed in subfolder of main domain:
example
www.mydomain.com/site1
www.mydomain.com/site2
www.mydomain.com/site3

when call a page on
www.mydomain.com/site1
if would like that my document root for this site point to /site1 folder and not to www.mydomain.com folder

Thank you

@lisamathew221
Copy link

iBOMMA - Watch and Download ibomma Telugu movies from ibomma.com. Watch Telugu movies in an excellent quality at the smallest file size.

@lisamathew221
Copy link

If you’re unsure where to find a casual mate, try Doublelist app with lots of sugar babies and independent escorts. All girls are incredibly beautiful and open to experiments with a stranger.

@lisamathew221
Copy link

If you live in Berkeley, Ca., and are looking for a Berkeley moving company. Then look no further than the New Day Moving company. We are a leading Berkeley moving company and our clients are happy with our work. Call us anytime to book your schedule.

@lisamathew221
Copy link

John Patrick University's School of Integrative and Functional Medicine university offers degrees & certificates in nutritional health.

@getandroid
Copy link

It helped me a lot to redirect my website which is for download free vpn without any plugin

@allin211
Copy link

allin211 commented Jan 4, 2023

i have used all the redirects listed here including image expire headers https://findapkmod.com/

@Kiankhan01
Copy link

Download Most Mod Apk for Android ...
https://apkspicy.com/

@Kiankhan01
Copy link

If you want to download Kinemaster Pro, you can download it very easily from this goolge. We can also download it from play store. But we need no watermark and no ads. That’s why we prefer to download it from Google.

Download Kinemaster Pro Mod Apk

@deependrashilpi
Copy link

Thank you sir for such a valuable Information

@deependrashilpi
Copy link

Thanks for the information contained in this valuable Content

@saqibqt
Copy link

saqibqt commented Feb 19, 2023

Ahh, Thankyou so much for the detailed article. I have implement the .htaccess on my Software Reviews & download website with the help of this article.

@rimi887
Copy link

rimi887 commented Feb 20, 2023

Thanks for this amazing information and content, I am also love to watch YouTube content but most of the time I prefer to to watch YouTube content in [YouTube Vanced](YouTube Vanced.

)

@AskApache
Copy link

Awesome, for more advanced htaccess examples see https://www.askapache.com/htaccess/

@gbwhatapps
Copy link

YouTube is beneficial to a user and YouTubers and people. Very useful versions were updated by this YouTube channel and complemented by the all Youtube Vanced Apk Download 2023

@gbwhatapps
Copy link

FMWhatsApp Apk Download Latest Version 2023 is a modified version of WhatsApp Messenger. You can download the latest version

@jimmy14525
Copy link

Thank you for providing a platform for endless entertainment and educational content. You're a valuable part of our digital world. vanced youtube

@Upsprit500
Copy link

Thank you so much
Sir for your supportive information and expert analysis

@Tommy5412
Copy link

Tommy5412 commented Apr 26, 2023

If you are a gamer, you must try the top best Unblocked games 66 on your school websites. Those are really helpful to play this game on your school systems. Just to try the all the games on that article. You might like those games.

@Soniya87
Copy link

Soniya87 commented May 2, 2023

Thank you very much for sharing such a nice Biography, it is very useful for me and everyone else. I'll be checking out frequently to read your new post, so it's unmissable to keep up.

@themarenas
Copy link

To solve an issue you must research it first Fmovies

@Leenaa1255
Copy link

Thank you so much for the information, I like it's Free Fire game

@Tommy5415
Copy link

Hi Guys Thank you so much for giving a such nice Net Worth information.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment