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]
@Insideaustralia1
Copy link

i will try it soon

@Insideaustralia1
Copy link

You have requested to move your VIP membership from Insight Enterprises Australia Practice Test Ltd to The Somerville Group. Here is your reseller change code:

@nisarbhatti111
Copy link

Download and Install Snaptube on Your Phone · Download the Snaptube APK file from the red button below. · Please enable "Unknown Sources" in your device ... https://snaptubeapk.media/

@waji0234
Copy link

waji0234 commented Sep 9, 2024

With our eyeshadow palette category, you are able to create your own unique eyeshadow palette brand. Our extensive range of shades, finishes, and textures allows for endless possibilities, from bold and vibrant hues to subtle and sophisticated neutrals.
https://aqgimel.com/product-category/eyeshadow-palette/

@Amelia128
Copy link

Redirect a single page

Redirect 301 /old-page.html http://www.newsite.com/new-page.html

Visit the new page

Redirect entire site

Redirect 301 / http://www.newsite.com/

Visit the new site

Redirect a folder to another domain

Redirect 301 /old-folder http://www.newsite.com/new-folder

Visit the new folder

Redirect old domain to new domain (retain path)

RewriteEngine on
RewriteCond %{HTTP_HOST} ^oldsite.com$ [NC]
RewriteRule ^(.*)$ http://www.newsite.com/$1 [R=301,L]

Visit the new domain

Redirect non-www to www

RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Visit
Dip Belt with Chain

@Jhon-doe12
Copy link

In .htaccess, you can set up various 301 redirects to manage site traffic efficiently. Redirect single pages or entire sites to new URLs, including subfolders and domain changes. Use rewrite rules to handle complex scenarios like query parameters or preserving paths during domain shifts. These rules ensure seamless user experience and maintain SEO integrity during site updates or migrations.

@sakeban
Copy link

sakeban commented Sep 13, 2024

Roblox fan? try out Fluxus best tool to uplift your roblox scripting.

@Samrina112
Copy link

Download the latest version of car parking multiplayer Mod APK from Google play store. In the game, you can drive and park various cars in different environments, complete parking missions, and explore open-world areas.

@Samrina112
Copy link

Survivor.io Mod Apk modified version will enable you to fight more freely and deal with the enemy better, so that you can easily explore the game world and experience the pleasure of adventure.

@noahUKUK
Copy link

When considering Shala Darpan, a person youtube vanced might think of its vital role in connecting teachers, students, and parents in Rajasthan. They could view it as a key tool for improving education, enhancing transparency, and fostering collaboration to boost students' academic achievements and overall development.

@Ayesha7253
Copy link

Ayesha7253 commented Sep 15, 2024

You have given good information about downloading FM WhatsApp APK. I saw the website but your way of explaining was very good.

https://fmoldversion.com/

@Ayesha7253
Copy link

You had information about downloading Yo WhatsApp APK. I liked this information very much, thank you sir.

https://www.fmapppro.com/

@Insideaustralia1
Copy link

This person is genious and owe me Hungry Jacks Menu Prices

@Samrina112
Copy link

Coin Master Moded APK is a game of young people everywhere, so we will exchange cards with the online community to make friends worldwide and have more good friends in the game and life.

@Ayesha7253
Copy link

You help us a lot, we like your articles very much.

https://www.yoapppro.com/

@alinccess
Copy link

WhatsApp Aero is a popular alternative version of the standard WhatsApp messaging application, offering users a variety of additional features and customization options. With WhatsApp Aero, users can enjoy enhanced privacy settings, such as the ability to hide their online status or disable read receipts. Moreover, it provides an array of customization options, including themes, fonts, and chat backgrounds, allowing users to personalize their messaging experience according to their preferences. Get from Apkwa

@GBWA002
Copy link

GBWA002 commented Sep 20, 2024

Thanks for sharing. GB WhatsApp is a popular modified version of WhatsApp official. You can use it with more features for daily messaging.

https://waplusapk.download/

@ffh4xapk-alt
Copy link

FFH4X apk  is a custom firmware for the Nintendo Switch that opens progressed homebrew highlights, counting cheats and framework changes. It’s user-friendly and broadly upheld by the gaming community, in spite of the fact that it comes with dangers like voiding guarantees.

@hooram33
Copy link

Thank you so mush for sharing this nice post if you want to play any action game than must play geometry dash APK .

@suzenjack
Copy link

9anime has gained a loyal following for its extensive library of anime series and films, offering everything from classic titles to the latest seasonal releases. Users appreciate its user-friendly interface, which makes browsing and finding shows easy. The site provides high-quality streams and multiple subtitle options, catering to a diverse audience. Additionally, the community aspect allows fans to discuss their favorite series and discover new recommendations. Overall, 9anime stands out as a reliable and enjoyable platform for anime lovers seeking a vast selection and a seamless viewing experience.

@noahUKUK
Copy link

Thank you for your kind words! It's great to hear YouTube Vanced that you find the content useful. Engaging with insightful posts regularly can truly enhance knowledge and spark new ideas. I look forward to sharing more valuable information, so stay tuned for future updates!

@marifahulquran
Copy link

Do you want to learn more about the Quran as an adult in Singapore? With home Quran classes Singapore, you can learn Islam’s holy book in a convenient and effective way. The purpose of this article is to explore how to find the best online Quran teacher for your needs as well as the benefits of Quran classes for adults in Singapore.

@theinstander
Copy link

Enjoy the ultimate music experience with Spotify Premium APK 2024! Listen to every playlist and song without any interruptions, completely ad-free. Take advantage of offline mode and enjoy unlimited skips to play the music you love. Now, every beat is in your control!

@therobertscott
Copy link

calculadora es una poderosa calculadora especialmente hecha para estudiantes, matemáticos, profesores y profesionales comprometidos con cálculos diarios. Calcula fracciones, divisiones, multiplicación, adición y resta.

@Jimmychohankhan
Copy link

In .htaccess, implement 301 redirects for the Goku Wallpaper platform to handle page, directory, or domain changes while preserving SEO. Use rewrite rules for advanced scenarios like query parameters or maintaining URL structures during complex migrations and updates.

@sakeban
Copy link

sakeban commented Oct 1, 2024

Looking for the best roblox scripting platform? It offers you multiple roblox executors including delta, Arceus X Neo and Wave.

@akhmed89
Copy link

akhmed89 commented Oct 2, 2024

I found recreating Spotify's design to be an immensely rewarding experience! As a dedicated user, I explored every detail, which deepened my appreciation and sharpened my design skills. For more insights and resources, get Spotify Premium App 2024.

@Abdullpasha
Copy link

Thanks for sharing this amazing content. to make your moments look amazing check out this Inshot Pro

@davidhammad
Copy link

Top Follow APK is perfect if you're looking to boost your Instagram likes and followers fast! Plus, you can even earn money by selling follower services

@kermitwarner
Copy link

This is a great set of .htaccess redirects! It covers everything from basic page redirects to advanced URL rewrites, making it super useful for SEO and website management.

If you're into customization, just like with GB WhatsApp, check out GB WhatsApp Pro at https://gbpro.pro for more control and enhanced messaging features!

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