Skip to content

Instantly share code, notes, and snippets.

@ScottPhillips
Created February 2, 2012 04:30
Show Gist options
  • Save ScottPhillips/1721489 to your computer and use it in GitHub Desktop.
Save ScottPhillips/1721489 to your computer and use it in GitHub Desktop.
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]
@serooo999
Copy link

The WSOP 1 million free chips is an incredible platform for both seasoned pros and newcomers to the game. The variety of tournaments and formats keeps things exciting, and the opportunity to play against some of the best in the world is unmatched. Whether you're competing for a coveted bracelet or just enjoying some casual online play, the WSOP consistently delivers top-notch poker experiences. Highly recommend it to anyone looking to test their skills or simply enjoy the thrill of the game!

@ronaldjames6548
Copy link

TikTokio is Tiktok video downloader to online download tiktok videos without watermark easily, download video from tiktok, free download tiktok video in mp3.

@mazseo
Copy link

mazseo commented Nov 30, 2024

The online movie watching site hindi and telugu movies for free. plz visit]..

@aniwave2k
Copy link

aniwave2kHiAnime.to is a free site to watch anime and you can even download subbed or dubbed anime in ultra HD quality without any registration or payment. By having only one ads in all kinds, we are trying to make it the safest site for free anime.

@lisa121c
Copy link

lisa121c commented Dec 1, 2024

Hi everyone,
I’ve been looking into some cool GitHub projects that integrate with Spotify, and I’m curious if anyone has experience using or contributing to any. I’m particularly interested in projects that enhance the Spotify experience, whether through custom playlists, integration with other apps, or even improvements to the Spotify Music Preferences Dashboard.

If anyone has found useful GitHub repositories or knows of any ongoing Spotify integration projects, I’d love to hear about them. Also, for those looking to make the most of Spotify, check out https://spotifypremiumapkdescargar.com/ for some great tips and tools.

Looking forward to your recommendations!

@rahulsinr
Copy link

thanks for providing the list of htaccess in place i have some problem related to htaccess and it solved now due to this github repo
Inat BOX

@tehrymijaz
Copy link

**Drive Zone Online MOD APK **takes the adrenaline-pumping action of the original game to the next level by offering unlimited resources and unlocked features. This enhanced version lets players access premium cars, customizations, and exclusive perks without grinding through the standard gameplay.

@alexhales2424
Copy link

These .htaccess examples simplify managing redirects, from single pages to entire domains. The rules for handling query strings and retaining paths during domain changes are especially handy. Similarly, Spotify ensures a smooth user experience with features like offline downloads and playlist syncing. Explore more at Spotify Premium APK for an upgraded music experience!

@alexhales2424
Copy link

These .htaccess redirect setups are incredibly useful, especially for managing seamless transitions between domains or adjusting URL structures. The examples for handling query parameters and preserving paths stand out for their practicality. Speaking of smooth transitions, Spotify offers a fantastic way to carry your music wherever you go, with features like offline listening and personalized playlists. Learn more about enhancing your music experience at Spotify Premium APK.

@alexhales2424
Copy link

Spotify Premium APK makes music streaming so much better. You can skip ads, download tracks, and enjoy endless skips without interruptions. Learn more at https://descargarspotapp.com.

@alexhales2424
Copy link

Spotify Premium APK completely transforms the listening experience. With no ads, offline downloads, and unlimited skips, it’s perfect for any music lover. Check it out at https://spotappdownload.com.

@Amelia128
Copy link

Amelia128 commented Dec 4, 2024

"Such an informative article! Sweaty feet can be so uncomfortable and even lead to issues like odor or infections if not managed properly. I appreciate the practical tips on how to keep feet dry and fresh, especially the advice on breathable footwear and using foot powders. This is a must-read for anyone dealing with this common but often ignored problem. Thanks for shedding light on it!"

@Haydenjoi
Copy link

Thanks for the comprehensive guide on common .htaccess redirects—super helpful for managing efficient site migrations and URL rewrites!

@techanzone
Copy link

Increasing the Instagram followers is now really easy. You can increase your Instagram followers by using the Top Follow APK. You just have to earn the coins by completing small tasks and you will have hundreds of free Instagram followers.

@kunseom
Copy link

kunseom commented Dec 5, 2024

This code is excellent for managing .htaccess redirects! I’ve used a similar method for handling URL rewrites on my site, https://capecoralconcretesolutions.com/. Redirects are crucial for preserving SEO and ensuring a smooth user experience during site migrations. Thanks for sharing!

@johnnysindev
Copy link

For Instagram followers apps, Insta up stands out as one of the best platforms. It’s user-friendly, efficient, and designed to help boost your profile’s engagement quickly, making it ideal for both personal and business use.

@Sitegen1
Copy link

Sitegen1 commented Dec 6, 2024

Dive into the electrifying world of Geometry Dash 2.2 APK, a fast-paced, rhythm-based platformer that challenges your reflexes and precision. With its engaging gameplay, vibrant graphics, and catchy soundtracks, this game has captivated millions of players worldwide. Whether you're dodging spikes or jumping through challenging obstacles, the Geometry Dash APK offers endless excitement for both casual gamers and hardcore enthusiasts. Ready to take on the beat? Start your journey now!

@tehrymijaz
Copy link

Amber’s success lies in its authentic flavors, affordability, and the convenience of their party trays and delivery services. Their dishes bring the comforting taste of home-cooked Filipino meals to the table, making them a popular choice for everything from casual meals to festive celebrations.

To explore their complete menu and learn more about their latest offerings, visit Amber’s official website at ambersmenu.com.ph.

@tehrymijaz
Copy link

Roblox scripting has gained immense popularity, allowing players to modify and create unique experiences in the game. To make the most of these scripts, you need a reliable executor that can run them smoothly. One of the top choices among Roblox scripters is Fluxus Executor. In this article, we’ll dive deep into what Fluxus Executor is, its features, benefits, and why it's a go-to option for many Roblox enthusiasts.
click here for more information

@tehrymijaz
Copy link

The world of mobile gaming has been revolutionized by simulation games, and Car Parking Multiplayer 2024 is leading the way. This game combines realistic driving with an open-world environment, allowing players to experience the thrill of parking challenges, car customization, and multiplayer interactions. Here’s a detailed look at what makes this game so engaging.

If you're interested in trying out Car Parking Multiplayer 2024 and exploring all these exciting features, check out carsparkingmultiplayer.com for more details and downloads.

@allwapro
Copy link

allwapro commented Dec 7, 2024

The latest update of GBWhatsApp Pro (v18.20) is a game-changer! 🚀 With enhanced customization options, improved privacy features, and new tools like message scheduling and voice changing, it's clear that the developers are committed to making our messaging experience even better. The ability to hide blue ticks and 'last seen' status adds an extra layer of privacy, which is fantastic. Highly recommend giving it a try if you're looking to elevate your WhatsApp experience! Visit Website Allwapro.com

@safizain2
Copy link

"The Spike Volleyball game is such an incredible experience for sports enthusiasts! 🏐 If you're a fan like me, you should definitely check out this amazing resource: Spike Volleyball Story for all the latest tips and tricks. It’s a must-visit if you want to master the game!

@safizain2
Copy link

The Spike Volleyball game is such an incredible experience for sports enthusiasts! 🏐 If you're a fan like me, you should definitely check out this amazing resource: Spike Volleyball Story for all the latest tips and tricks. It’s a must-visit if you want to master the game!

@safizain2
Copy link

if you’re into design and creativity, the Canva Mod APK is a game-changer. It unlocks premium features for free, making it perfect for creating stunning visuals.

@tehrymijaz
Copy link

A binary number to decimal converter is a method used to translate binary numbers, which are composed of only 0s and 1s, into decimal numbers, which are the standard number system used by people. Each digit in a binary number corresponds to a power of 2, with the rightmost digit representing the smallest power, and the powers increasing as you move to the left. To convert a binary number into decimal, you multiply each digit by the power of 2 that corresponds to its position, and then add all the resulting products together.

@aniwave31
Copy link

Aniwave is a top online anime streaming site where you can watch and download
English Subbed and Dubbed anime for free.

Aniwave

@Walt72
Copy link

Walt72 commented Dec 9, 2024

Digital banking reduces the need for paper, contributing to environmental sustainability. Remote Services: Reduced reliance on physical infrastructure decreases the carbon footprint associated with commuting and branch operations. NL casino reviews online

@Amelia128
Copy link

The Battery Operated Foot Scrubber offers a convenient and efficient way to keep feet smooth and soft. With its portable and easy-to-use design, it provides a spa-like experience at home, ensuring quick and hassle-free foot care.

@techanzone
Copy link

Looking for great names related to any thing whether It is an animal, team, or business, you can head over to the namespallete.com

@CapCutModsAPKs
Copy link

The latest update of FM WhatsApp (v10.10) is a game-changer! 🚀 With enhanced customization options, improved privacy features, and new tools like message scheduling and voice changing, it's clear that the developers are committed to making our messaging experience even better. The ability to hide blue ticks and 'last seen' status adds an extra layer of privacy, which is fantastic. Highly recommend giving it a try if you're looking to elevate your WhatsApp experience! Visit Website FMAppsPlus.com

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