Instantly share code, notes, and snippets.

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]
@purse9644

This comment has been minimized.

purse9644 commented Mar 26, 2014

Hi, is it possible to create a 301 redirect for the following URL string:

Original URL:
http://www.example.com/old-directory/blog-post-5

Desired destination URL:
http://www.example.com/new-directory/blog-post-5

@ezpaider

This comment has been minimized.

ezpaider commented Apr 2, 2014

@purse9644, in order to redirect from your original URL to the new desired destination, you can do the following:

Options +FollowSymLinks RewriteEngine On RewriteRule ^(.*)/old-directory/(.*)$ $1/new-directory/$2 [R,L]

@CouponFury

This comment has been minimized.

CouponFury commented Apr 14, 2014

Is it possible to redirect from /example/ to /example/index.php?
We are using Disqus as a blog engine and it is very picky about matching exact urls.

@Netzie

This comment has been minimized.

Netzie commented Jul 11, 2014

Hi
Can you help me with moving old URL/Domain http://testthis.dk to new domain http://arbejdhjemme.com
Without +FollowSymLinks that my host don't want/allow and I want to catch all subdomains and files
So if a request comes for testthis.dk/start-here
it will be send to arbejdhjemme.com/start-here

I tried most of the examples above and testthis.dk/start-here results in this arbejdhjemme.comstart-here (no slash) :-(
Thanks for your time and help

@nachogarrone

This comment has been minimized.

nachogarrone commented Jul 11, 2014

Hi, do you know how to redirect always (in all subfolders) from myweb.com/index.php to myweb.com/

@mgoldsteinsv

This comment has been minimized.

mgoldsteinsv commented Jul 24, 2014

Great examples, but I have one a little more complex that I can't figure out. Old website had blog entries in mywebsite.com/blog/year/month/blog-name. New site is just mywebsite.com/blog-name. For example: mywebsite.com/blog/2013/06/my-blog-name needs to redirect to mywebsite.com/my-blog-name.

Any help is greatly appreciated.
Mitch

@rautamiekka

This comment has been minimized.

rautamiekka commented Aug 1, 2014

How to redirect from a folder into that folder's subfolder ?

www.example.com/afolder/ -> www.example.com/afolder/targetfolder/

@johnking7

This comment has been minimized.

johnking7 commented Oct 30, 2014

Thanks man, this just saved me a whole bunch of time!

@agarridob

This comment has been minimized.

agarridob commented Dec 2, 2014

Hi!
Is it posible to redirect from www.domainx.com to www.domainy.com/folderz?
What I want to get is that when I go to www.domainx.com/page.html it automatically goes to www.domainy.com/folderz/page.html, without changing the url on the browser. Is that feasible?
Thanks a lot!

@ghost

This comment has been minimized.

ghost commented Jan 20, 2015

I'm attempting to redirect URLs that have multiple parameters for example: http://www.example.com/index.php?p=product&id=10&parent=0 to a clean URL on another domain like http://example2.com/product/product10/

Can anybody give me a few pointers please?

@sujitrulz

This comment has been minimized.

sujitrulz commented Jan 29, 2015

Hey, how can i redirect old domain to new domain while retaining the path after the old domain name. for instance oldomain.com/test/ to newdomain.com/test/

@development93

This comment has been minimized.

development93 commented Apr 7, 2015

Dear Friends,
I just want to redirect this page in a proper category page. so please give me a guide for that..Page is mention bellow, please follow as..
http://www.delhidentalacademy.com/courses_details.php?id=Oral_Surgery_Course
to
http://www.delhidentalacademy.com/Oral_Surgery_Course
I look foreword to your response quickly.....

@GnosisMediaGroup

This comment has been minimized.

GnosisMediaGroup commented May 21, 2015

This is a terrific post. Just wanted to add: if you have a Wordpress site with a permalink htaccess directive already in place, AND you wish to do a 301 from domainx.com to domainy.com/subfolder, then you need to do this:

Redirect 301 / http://domainy.com/subfolder?

Adding the "?" will add a "?" at the end of the redirect URL. This will force the browser to view anything after the "?" as parameters. Otherwise, the permalink redirect will "break" your 301 redirect. And if you remove the permalink redirect, you're going to break the 301 redirect.

I found this out the hard way by banging my head against the server for like a week.

@guidoschmidt

This comment has been minimized.

guidoschmidt commented May 23, 2015

Thank you very much for this incredible helpful gist :) everything I need to know about .htaccess files in one place 👍

@seemoretate

This comment has been minimized.

seemoretate commented May 25, 2015

Hello,
I have a site using permalinks. and it works perfect. aka

http://www.mysite.com/cartypes.php?cartype=123 and the akin permalink http://www.mysite.com/red.php

the above works great. Now on a different server with a different site root. I have it so were a person to come using http://m.mysite.com they see the mobile site. this all works fine but then I want to use a perma link for this. thus. This site which has its own site root. I have added

Redirect 301 /cartypes.php?cartype=12 http://m.mysite.com/red.php

the above gives me a 404 yet were i to go to http://m.mysite.com /cartypes.php?cartype=12 I see the related page.

I have tried everything and been to a thosand webpages looking to resolve this. thus am very grateful for any input your side.

regards

@OgonTejasFeuer

This comment has been minimized.

OgonTejasFeuer commented Jun 3, 2015

Hello,
I need help redirecting from one subdomain to another while maintaining same path({REQUEST_URI}
i.e all requests with this context path (pv5/v8/1)
http:/sub1.example.com/pv5/v8/1/app/cfaexcel/level1.html?u=d67b9c80-1e6a-4ac3-a07a-aa1e9e86c47b
should be redirected to
http:/sub2.example.com/pv5/v8/1/app/cfaexcel/level1.html?u=d67b9c80-1e6a-4ac3-a07a-aa1e9e86c47b

@alimuzzaman

This comment has been minimized.

alimuzzaman commented Jul 23, 2015

Can anybody help?
I want like this.
www.example1.com/index.php
to
/home/example2.com/index.php
But without hard coding the host. so that this will also work
www.example2.com/index.php
to
/home/example2.com/index.php

@adekbadek

This comment has been minimized.

adekbadek commented Sep 2, 2015

Just wanted to add:
If you are working with WordPress, add your redirects ABOVE WordPress rules

@ektasurya

This comment has been minimized.

ektasurya commented Sep 2, 2015

i m working with core php
my url is like http://www.example.com/shop.php?b_id=277

i want to make it like
http://www.example.com/oral

@sailingbo

This comment has been minimized.

sailingbo commented Sep 18, 2015

Here's what I'm having a problem with...
http://juniorcaptains.com redirects to http://www.juniorcaptains.com - Great...this is what I want.
However,
http://juniorcaptains.com/blog redirects to http://www.juniorcaptains.com - This is no bueno. I just need it to add the www., so it will still go to the /blog/ WPMU site.

Is this an .htaccess thing? Thanks in advance!

@sibasish22

This comment has been minimized.

sibasish22 commented Sep 25, 2015

Hi All,
I want to redirect http://www.example.com/contact.php?no_direct=true to http://www.example.com/contact.php

Any help is greatly appreciated?

@fbayer

This comment has been minimized.

fbayer commented Sep 25, 2015

Files moved to another directory: test-a >> test-b
Old links to any file within the test-a folder have to be redirected to the new folder - test-b.

http://www.domain.com/Test-A.htm?variable=1&pathvar=tests/test-a/
should be redirected to
http://www.domain.com/Test-B.htm?variable=1&pathvar=tests/test-b/

The htaccess file is located in the root of the web project and works fine for other rewrites, but not for this one:
RewriteRule ^/Test-A.htm?variable=1&pathvar=tests/test-a/(.*)$ http://www.domain.com/Test-B.htm?variable=1&pathvar=tests/test-b/$1 [L,R=301]

Does anyone see the problem? Thanks in advance.

@pauly69

This comment has been minimized.

pauly69 commented Oct 7, 2015

Hi,

Google showing Duplicate Title and description Tags Errors in GWT under HTML Improvements duplicate meta description - 4 and duplicate title tags - 4.

/sign-up.html
/sign-up.html?m

/
/?m

So, I need search engines not to index the ?m parameter at the end of my website url. I guess this is a development issue. In the .htaccess I found the code below that might lead to the m parameter issue on google. Does someone know how to fix it?

Redirect urls based on a query string parameter

RewriteCond %{QUERY_STRING} ^(.&)?view=mobile([^&])&?(.)?$
RewriteRule ^(.
)$ /$1?m%1%3 [CO=is_mobile:1:%{HTTP_HOST},CO=disable_mobile:0:%{HTTP_HOST},L,R]

RewriteCond %{QUERY_STRING} ^m_(.&)?view=full([^&])&?(._)?$
RewriteRule ^(.*)$ /$1?%1%3 [CO=disable_mobile:1:%{HTTP_HOST},L,R]

I am also confused because my mobile version is /mobile and not m? so I don't understand how Google managed to index the m parameter.

Also when I inserted the canonical url on the /mobile version and the alternate url on the desktop version google mobile search delivered the following

www.mysite.com (mobile-friendly)

www.mysite.com/mobile/sign-up.com (mobile-friendly)

but before the changes:

www.mysite.com (mobile-friendly)

www.mysite.com/sign-up.com (mobile-friendly)

So this tells me that google detected the mobile site regardless of the changes I made after. As you can see it says Mobile-Friendly (www.mysite.com/sign-up.com) So if it wasn't for the ?m parameter I would not have any duplicate content. So how am I to fix this? It is a nightmare.

@criboats

This comment has been minimized.

criboats commented Oct 8, 2015

Hi!
Looking to redirect the following:

http://www.url.com/distribution-city/?distributor=MFhc
to
http://www.url.com/newdirectory

I'm stumped.

Please and thanks in advance!

-Sean

@MunirajM

This comment has been minimized.

MunirajM commented Oct 13, 2015

Hi,

I have two below 301 redirects on my htaccess file.

Redirect 301 /test/sample /newurl
Redirect 301 /test/sample/redirect /subpage

When I tried to check /test/sample/redirect, it should be redireced to /subpage however, it is being redirected to "newurl/redirect" which leads to 404 page. I have tried with changing the order as well on the htaccess file, but no luck.

Could anyone please help me to solve this. Thanks in advance.

@svilenzhelev

This comment has been minimized.

svilenzhelev commented Oct 18, 2015

Hi, first of all, congratulation! Very helpful info.
I need an advice, how to redirect to the last category in the path. For example:
www.mysite.com/category/subcategory/subcategory1/ to www.mysite.com/subcategory1/
Doesn't matter the number of categories, I want to redirect to the last. I successfully create a redirect but I want to create an universal rule for all categories, not to describe one by one. Is it possible?

@svilenzhelev

This comment has been minimized.

svilenzhelev commented Oct 19, 2015

So, my conclusions are that can't create an universal rule. The rule which i use is OK,

RewriteRule ^(.)/(.)$ /$2 [R=301,L]

but also redirect the other resources like css, js, jpg etc. I use three rules to do what I want:

RewriteRule ^my-category/(.)$ /my-category [R=301,L]
RewriteRule ^(.
)/my-category$ /my-category [R=301,L]
RewriteRule ^(.)/my-category/(.)$ /my-category [R=301,L]

It will be great if somebody give some optimization.

@samansohail

This comment has been minimized.

samansohail commented Nov 6, 2015

Hi, is it possible to create a 301 redirect for the following URL string

oldpage.php //:http:www.example.com / newpage.php

@miftahululum

This comment has been minimized.

miftahululum commented Jan 3, 2016

good informent.
http://www.dj-music.info/

@Kazzje

This comment has been minimized.

Kazzje commented Jan 21, 2016

Hi,

What if I want to reach this:
blog.example.de/en_GB redirecting to blog.example.com/en_GB

How can I write a condition?
Thanks a lot!

@chaithanya-vk

This comment has been minimized.

chaithanya-vk commented Feb 9, 2016

Hi,
How to redirect http://example.com/abc to http://www.example.com/abc . I have .htaccess in root folder and sub-folder (abc) as well. How and where should i write condition?

Thanks.

@thewismit

This comment has been minimized.

thewismit commented Apr 19, 2016

Hi Scott. This is a great gist, thank you! I'm hoping you can help me do the following and I apologize if it's already been answered in your post or the comments, I'm not very familiar with Apache and am not always sure of what I'm reading.

I want to redirect http://domain.com to http://blog.domain.com - I've got that part by using this:

RedirectMatch "^" "http://blog.domain.com/"

However, I'd also like to have requests to https://domain.com/subdirectory not be rewritten/redirected. Currently any attempt to access a subdirectory gets redirected to http://blog.domain.com.

Can you please advise?

@ajaykr089

This comment has been minimized.

ajaykr089 commented Jun 8, 2016

Hi Scott,

Can you please help me to stop https redirect for a particular url, Please find my current .htaccess

ssl

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

I want below url to not redirect on https

https://www.domain.com/setup/abc/{ID}
https://www.domain.com/setup/abc
etc..

basically i want urls not to redirect which are including "/setup/"

Any help will be much appreciated
Thanks :)

@tripledm

This comment has been minimized.

tripledm commented Jun 9, 2016

Hi Scott,

I have a tricky redirect and hoping you or someone can help me.

The redirect I need must remove both numbers and ".html", so all the URLs with a number at the end.

Example:
Original URL: http://www.domain.com/articles/sampe/2015-05-14/post-name/11234566.html
New URL: http://www.domain.com/articles/sampe/2015-05-14/post-name/

Thank you in advance!

@dduboy

This comment has been minimized.

dduboy commented Jun 12, 2016

Hi !
I have a main domain website http://www.maindomain.com with its own .htacess working well. This main domain is made with WordPress, under the path httpdocs/ and all is working well. I have also some subdomain : http://my-subdomain.maindomain.com on my server that i don' t need anymore, but i don't want to loose the rank and links. So i would like to redirect them permanently to the main domain's corresponding page or virtual folder.
The subdomain is under this path on the server Apache (i didn"t choose this, it is done automaticaly when i create it throught plesk : subdomains/my-subdomain-A/httpdocs/
It has no files Inside the directory at all, just some virtual categories and subcategories folders, and everything is in php.
So i tryed this and i've sent the .htaccess file in the "subdomains/my-subdomain/httpdocs/" root directory httpdocs. But no way...does'nt work.

Options +FollowSymlinks
RewriteEngine on
RedirectPermanent /afolder/page1.php http://www.maindomain.com/category1/subcategory1-new/page1-new/
RedirectPermanent /page2.php http://www.maindomain.com/category1/subcategory1-new/
RedirectPermanent /page3.php http://www.maindomain.com/category1/subcategory1-new/page2-new/
etc..

When i use this method for redirectpermanent, it does'nt work (error 500). I have searched for some ideas everywhere, but Nothing seems to work...any help will be much appreciated !! Thank you in advance !

@beautyraj123

This comment has been minimized.

beautyraj123 commented Jun 14, 2016

current url: http://kheralab.com/agra1/cat.php?url=shi-ram-mantras

Expected url: http://kheralab.com/agra1/cat.php/shi-ram-mantras

what is the code i have to use can u suggest me??

@anavasis

This comment has been minimized.

anavasis commented Jul 4, 2016

Can you please help me in making some redirects, i will mention them below:

anavasis.gr to https://www.anavasis.gr
https://anavasis.gr to https://www.anavasis.gr
all sites having /index.php/ like https://anavasis.gr/index.php/ to be redirected to https://www.anavasis.gr/
also all sites having /index.php/ like https://www.anavasis.gr/index.php/ to be redirected to https://www.anavasis.gr/

please give all the text i have to put to .htaccess because i have no knowledge about the specific purpose

@charlesbelisle

This comment has been minimized.

charlesbelisle commented Jul 14, 2016

I'm a little bit confused about these URL REWRITE rules so I'll ask directly my need ;)

It's a little bit non common but I would like to REDIRECT everyone going to the "/" path to a http://newdomain.com straight forward but URL REWRITE the rest of the URL if filled (a subfolder + file like "/subfolder/XXX.YYY" or even only a file like "/XXX.YYY")

Could you help me figure it out please? :)

@aresthelord

This comment has been minimized.

aresthelord commented Jul 14, 2016

I am little bit in trouble here . don't have a host but have a domain and also wanna redirect this domain to another domains subdomain. Is it possible to achieve this without using .htaccess?
let me be a little more clear.
i want to redirect http://www.dodtechnologies.com to http://dodtech.biranneyesorun.com .
While I am doing this i want the url shown as entered

http://www.dodtechnologies.com like this. For example when I enter http://www.dodtechnologies.com/products I want it to show the contents from http://dodtech.biranneyesorun.com/products.

Can you please direct me to the right direction?

@mdehaan

This comment has been minimized.

mdehaan commented Jul 22, 2016

How to Redirect specific page on specific domain alias to https/SSL.

The webhosting is setup with multiple domain aliases on the same vhost. It needs to redirect a specific page on a specific domain alias to https.

domain-a.com
domain-b.com
domain-c.com

http://www.domain-c.com/contact needs to redirect to https://www.domain-c.com/contact

The other domains, domain-a.com and domain-b.com don't need to redirect /contact to https

@parulkapoor84

This comment has been minimized.

parulkapoor84 commented Jul 26, 2016

Hi,
Can you please help me what code to write in .htaccess file...
How can i redirect from www.old-domain.in/anypage to www.new-domain.com?
I want to redirect my whole website pages to my new websites's home page..
Please help me...

Thanks in advance

@patelhardik1011

This comment has been minimized.

patelhardik1011 commented Aug 1, 2016

Hi,

can you please help me to resolve my below issue :

I have one domain named http://cakephp.com Currently I am accessing its admin url using this url : http://cakephp.com/admin

I want to access admin url using this url : http://admin.cakephp.com I have tried some examples but they are redirecting me to http://cakephp.com/admin this URL. But I want to show this http://admin.cakephp.com in address bar.

I have project in CakePHP 3.x. So Can you please tell me that how can I achieve this functionality ?

Thanks in Advance.

@fnasimi1

This comment has been minimized.

fnasimi1 commented Aug 12, 2016

Hi Guys,

I want to redirect few folders and subfolders from one domain to another domain with different folder names (page names), first level pages are redirecting bu on second level I get 404 .
redirect domain1.com/xyz http://domain2.com/qwe
anybody can help?

@chriscambell

This comment has been minimized.

chriscambell commented Aug 24, 2016

Hi guys, so I've got a wordpress site which looks like:

OLDURL.com
OLDURL.com/content
OLDURL.com/content/subcontent

and I need to redirect all pages sharing that same root URL to:

subdomain.NEWURL.com
subdomain.NEWURL.com/content
subdomain.NEWURL.com/subcontent

How do I do this without going in and adding manual redirects to every single page?

@issuru

This comment has been minimized.

issuru commented Sep 1, 2016

GuidoSchmidt commented on 23 May 2015

Thank you very much for this incredible helpful gist :) everything I need to know about .htaccess files in one place 👍

Exactly. Cheers

@twpeach

This comment has been minimized.

twpeach commented Sep 6, 2016

Hi,

Thanks for this great article. But my situation is a little bit more complex.

Do you know how to redirect the following urls:

Old: https://twpeach.blogspot.com/2014/12/emilys-day.html
New: http://twpeach.com/baby/

Which comes with different domain name & different post id though! Thanks a bunch!!

@dbaja70

This comment has been minimized.

dbaja70 commented Sep 8, 2016

Hi,
i have to redirect old link
kontakt.php?lang=sr
to new page
index.php?lang=sr#CONTACT

I tried with rewriterule:
RewriteRule ^kontakt.php?lang=(sr|en)$ /index.php?lang=$1#CONTACT [NE,R]
but, as result, i get this:
http://www.domain.co.rs/index.php#CONTACT?lang=sr

Why rewriterule change order of parameter lang and anchor #CONTACT???

@bobby131313

This comment has been minimized.

bobby131313 commented Sep 8, 2016

I've been playing with this for a week with no luck, maybe you can help me. I want to 301 Redirect......

http://site123.com/t/[number]
to
http://site456.com/forum/topic.asp?TOPIC_ID=[number]

Would greatly appreciate any help.

@rjsnh1522

This comment has been minimized.

rjsnh1522 commented Sep 22, 2016

hii hope anyone can help my problem is i have this rule in my htaccess with some other rules

RewriteEngine On
RewriteRule ^work(.)/([^/]) work-single.php$1?slug=$2 [QSA]

what it basically does that it takes the slug value and pass it to the work-single.php . So my only one page work-single.php is used to show my all projects. work is the virtual directory which does not exist in real but it is added on url

what I want to do is like when ever any user enter like ex -[ ("upasna-group-self-branding") this will change from project to project it is comming from other page or database ]

https://www.mydomain.com/work/upasna-group-self-branding/ I want them to redirect to
https://www.mydomain.com/work/upasna-group-self-branding

and when they enter like https://www.mydomain.com/work/ or https://www.mydomain.com/work i want them to redirect back to https://www.mydomain.com/ourwork.php

please help me to write this

@atlarep

This comment has been minimized.

atlarep commented Sep 28, 2016

I want redirect when people try to browse through the /includes/ sub-directory of my website (where the java scripts and config files are), but when I do it, all the java scripts don't work on the site. Is there a way to do this without breaking java script?

@mpourkos

This comment has been minimized.

mpourkos commented Oct 8, 2016

Redirect to different domain.
current url: http://www.sbs-studies.com

Expected url: https://www.sbs-studies.gr

what is the code i have to use can u suggest me??

@imuneer

This comment has been minimized.

imuneer commented Oct 25, 2016

Excellent piece of script set

@unitycoder

This comment has been minimized.

unitycoder commented Nov 18, 2016

Only this worked for me with wordpress

  • redirect all traffic from old domain to new domain, in same hosting
  • new domain is add-on domain
  • wordpress is installed in folder (not in root)
  • placed on top of the .htaccess in yourblogfolder/ (the wordpress installation folder)
RewriteCond %{HTTP_HOST} ^old\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.old\.com$
RewriteRule ^(.*)$ "http\:\/\/new\.com\/yourblogfolder\/$1" [R=301,L,QSA]
@alankeys

This comment has been minimized.

alankeys commented Dec 6, 2016

Question about 301 redirect / modrewrite

Pleas I would apprec iate any help in you understand mod rewrite...
So far I have not managed to create my needed redirect.

here is my current URL : mysite.net/doc.php?title=john

needs to redirect to : mysite.net/doc.php?renamed=john&id=3340

so am adding 'id' and renaming the variable 'title'.

does anyone know the setting for this ??

@arpita21

This comment has been minimized.

arpita21 commented Jan 12, 2017

i want to redirect page
http://domain.com/cg.php/men/accessories
to
http://domain.com/men/accessories

manual enter 1 url then auto redirect main domain and 2 url.

@ryallamraju

This comment has been minimized.

ryallamraju commented Jan 13, 2017

It looks its good post for my problem, I have website hosted in openshift for instance http://example-products.rhcloud.com/allProducts and this will list out all the available products but if query param added to the above url like this http://example-products.rhcloud.com/allProducts?prodId=25, it displays only one product and everything working fine. But I have created domain in godaddy for instance http://products.com and forwarding to http://example-products.rhcloud.com/allProducts which is working but when I add query param to http://products.com/?prodId=25, its not working. What is the problem and what should be done in order forward the request to http://example-products.rhcloud.com/allProducts?prodId=25 from domain http://products.com/?prodId=25 with query param

@rickbeacham

This comment has been minimized.

rickbeacham commented Jan 21, 2017

Try adding (.*) at the end.

@rickbeacham

This comment has been minimized.

rickbeacham commented Jan 21, 2017

For some reason when i add this 'redirectMatch 301 ^(.*).html $1' to .htaccess i get:
{baseurl}/index/ for the home page. But everything else is working fine though.
Why is the happing?

@ghost

This comment has been minimized.

ghost commented Jan 24, 2017

I'm trying to figure out how to do this type of redirect:

change this:
/page/{category}/
to this:
/page/?category={category}

Any suggestions?

I'm basically trying to just reverse this one:
RewriteRule ^([^/d]+)/?$ index.php?id=$1 [QSA]

@amdrade

This comment has been minimized.

amdrade commented Jan 25, 2017

@Buddika1983

This comment has been minimized.

Buddika1983 commented Jan 28, 2017

Hi

I want to redirect my old domain each every pages to my new domain

www.olddomain/news
to
www.newdomain/news

How to do this kind of redirection

@lhesky

This comment has been minimized.

lhesky commented Mar 6, 2017

Hi Sir,
I am trying to write a htaccess in mod_rewrte

i have a search textbox in default .php and redirect from jquery in window.location
window.location.href="search.php?strname="+strname;

i get the parameter variable from search.php
http://localhost/profile/forms/search.php?strname=leo

i used this rule but i cannot get the way i want below
RewriteRule ^search/([^/.]+)$ search.php?strname=$1

to look this way. Please help me.?
http://localhost/profile/forms/search/leo

@Radmation

This comment has been minimized.

Radmation commented Mar 20, 2017

Thanks for this! Huge help!

@cyberboffin

This comment has been minimized.

cyberboffin commented Mar 31, 2017

How to use [L] transparent to make a redirect a directory file url be in the site index

E.g

Redirect https://aimtoget.com/board/3/Celebrities

To be https://aimtoget.com/board/3/Celebrities

@goatcloud

This comment has been minimized.

goatcloud commented Mar 31, 2017

I have a bit of a curious one. I had a former WordPress website, let's call it http://example.com. Full blown site, with pages, posts, categories, tags, etc.

I want to redirect every single URL from example.com to https://newwebsite.com/page

I set up a site redirect at the domain registrar to do that, but now I get many 404s upon redirection, like https://newwebsite.com/page/tags/tag1 or https://newwebsite.com/category/category1 or https://newwebsite.com/page/post5 and the like

I'm not sure if I can use the .hatccess file at https://newwebsite.com to accomplish this or if I have to set something up at the registrar for example.com.

Any ideas?

Solved my own problem. Maybe this will help someone else:

  1. Removed the redirect on example.com at registrar. Set the nameservers for example.com to a place I control.
  2. Created an "add on" domain for example.com via cPanel.
  3. Created an .htaccess file at the "holding" add-on domain for the old domain and added the following:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.example.com$
RewriteRule ^/?$ "https://newwebsite.com/page/" [R=301,L]

ErrorDocument 404 https://newwebsite.com/page/

@vaibhav-sidapara

This comment has been minimized.

vaibhav-sidapara commented Apr 4, 2017

Possible to do redirect for

www.example.com/abc -> abc.example.com

in both cases, the root directories are same, need to redirect to a subdomain without affecting the project execution.

@AmitKumariws16

This comment has been minimized.

AmitKumariws16 commented Apr 7, 2017

In cakephp 3 is Possible to redirect.
example.com to username.example.com.

@jphoke

This comment has been minimized.

jphoke commented Apr 17, 2017

Having a bit of trouble working this out .

Old URL
http://www.foo.com/subdir/
Moving this to
http://newdomain.com/

I want to redirect any /subdir/ path including anything passed via GET string to the newdomain

ex:
http://www.foo.com/subdir/index.php?bar=2
to
http://newdomain.com/index.php?bar=2

or http://foo.com/subdir/othersubdir
to
http://newdomain.com/othersubdir

Thanks in advance

@ruifct

This comment has been minimized.

ruifct commented Jun 3, 2017

hi guys, how can I redirect all the pages of www.canlibahis.io to www.canlibahisio.com, keeping the same url structure? The site is already copied on the new domain. Thanks

@emmalinnery

This comment has been minimized.

emmalinnery commented Jun 17, 2017

Hello,
I would be grateful for any input, I have the following in my htaccess file

this is to force to index file rather than just mysite.com it will give mysite.com/index.php

RewriteEngine On
RewriteBase /

#only for the root directory
RewriteCond %{REQUEST_URI} ^/$
#if the uri is not already index.php
RewriteCond %{REQUEST_URI} !^/index.php [NC]
RewriteRule ^$ /index.php [R=301,L]

the above works great, when ever a punter goes to mydomin.com it directs the punter to mydomain.com/index.php

I have an issue thought
The site is multi lingual, and I have also mysite.com/fr/

how can I force were someone to just type mysite.com/fr/ to force going to mysite.com/fr/index.php

Thank you for looking anyway lol

cheers

@dupls

This comment has been minimized.

dupls commented Jun 26, 2017

I have an entire website that I want to redirect to a new website folder.
#Redirect an entire site:
Redirect 301 / http://newdomain.com/new-folder
Which works, BUT, if people have an old link the first part www.newdomain.com is replaced but the rest of the link is added to the end, which of course doesn't exist anymore. I want to make sure any old bookmarks resolve to the newdomain.com/new-folder regardless of what they are.
I also tried.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^subdomain.newdomain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.subdomain.newdomain.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+..+.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}.txt(?:\ Comodo\ DCV)?$
RewriteRule ^phprimer.*$ https://newdomain.com/new-folder [R=301,L]
RewriteRule ^/?$ https://newdomain.com/new-folder [R=301,L]
Again the first part of the rewrite works so the path is newdomain.com/ but since the rest of the path is tagged on and doesn't exist I get 'Page not found'.

Any direction would be appreciated.

@Zuz66

This comment has been minimized.

Zuz66 commented Jul 4, 2017

Hi,

I have a small problem I hope someone can help me

I redirected all articles made in wordpress from

/%category%/%post-name%/ to /%post-name%/

to make this i use this in htaccess

RedirectMatch 301 ^/([^/]+)/([^/]+)/([^/]+)/$ https://www.site.com/$3

all is fine, categories url are rispected, but i have problem with pagination

when category is like https://www.site.com/category/
clicking on https://www.site.com/category/page/2/ results are wrong

instead is ok with https://www.site.com/category/sub-category/
clicking on https://www.site.com/category/sub-category/page/2/ result is correct is goes on second page of category

how can i solve?

thanks!

@kautukbhatnagar

This comment has been minimized.

kautukbhatnagar commented Jul 12, 2017

Hi,

how can i redirect all links of my site :

https://www.mysite.com/mywordpressfolder/
to
http://www.mynewdomain.com

both mysite.com and mywordpressfolder has separate WordPress installed.
should i write rule in mywordpressfolder .htaccess file ?? what rule it should be ?

I am helpless as of now !

Thanks in advnace

@Ayla77

This comment has been minimized.

Ayla77 commented Aug 14, 2017

How can i useful .htaccess file which is the best redirection PHP script using my websites - https://www.bestasiantours.com/ to http://www.travelvedas.com/ both my sites and we have change my website strategy.

@viswanathkk

This comment has been minimized.

viswanathkk commented Oct 12, 2017

i want to rewrite
my url is like https://dinkhoocom.ipage.com/APPS/

i want to make it like
https://dinkhoo.com

@viswanathkk

This comment has been minimized.

viswanathkk commented Oct 12, 2017

thanks in advance

@gediminaskv

This comment has been minimized.

gediminaskv commented Oct 13, 2017

@viswanathkk Buy a domain from your hosting provider and you will have a dinkhoo.com ;)

@n0risc

This comment has been minimized.

n0risc commented Nov 9, 2017

original
www.example.com/1000

redirect masked
www.example.com/?id=1000

More or less trying to obtain a pretty link for the sites root for any number 0 to 99,999
www.example.com/1234
but i need to pass the 1234 as a query string
www.example.com/?id=1234
but still maintain the original url in browser
www.example.com/1234

Additionally, www.example.com/1234 should be displayed in the browser no matter if the request url is www.example.com/1234 or www.example.com/?id=1234 Essentially reverse protected.

Possible?

@normarharris209

This comment has been minimized.

normarharris209 commented Nov 18, 2017

i want to redirect my images from google images search to my page where those images are existing on my site so i need .htacces code to do something like this. please help me

@patrmich

This comment has been minimized.

patrmich commented Nov 22, 2017

Hello,

In my website, I have some urls with the following shape :

There is no need neither to display nor to index such Urls (crawled only by robots but not used by website visitor)
In addition, they can be regarded as duplicate content

I wonder whether it is possible to **make a 301 redirection :

  • from any urls with n=
    
  • to the url content located before the question mark**
    

I thank anyone in advance for any help in this matter.

Patrick

@sugrob4

This comment has been minimized.

sugrob4 commented Dec 10, 2017

HI!
How do I execute the redirect in RewriteRule on these links;
from https://mysite/product/1
to https://mysite/product/1-some-thing-else

@sugrob4

This comment has been minimized.

sugrob4 commented Dec 10, 2017

redirect 301

@chakravarthykalyan90

This comment has been minimized.

chakravarthykalyan90 commented Dec 11, 2017

My problem is URL should look like http://example/test-2.html but content should come from http://example/test.html?p=2. Please help how to achieve it with htaccess file.

@maximumplay007

This comment has been minimized.

maximumplay007 commented Dec 14, 2017

Hi,
I have 2 domain
newdomain.com and
olddomain.com/folder/

I want to mask olddomain.com/folder to newdomain.com and want to keep the domain constant to newdomain.com not matter I click on any link but the domain should be newdomain.com

Please help

@eshrinivasan

This comment has been minimized.

eshrinivasan commented Dec 23, 2017

I moving my drupal site index.html from www.example.com/demo to www.example.com while keeping all the js, css, images, font etc within the "demo" folder. I no longer want to display "demo" in the url but still the js, css urls will have demo in them. What would be my redirect condition or rewrite rule in this case?

@CaptSpaceBat

This comment has been minimized.

CaptSpaceBat commented Dec 31, 2017

Hi, I hope someone can point out what I am doing wrong in my .htaccess file

I have a domain which has 2 folders - folder1 & folder2

Unless the request is specifically for folder2, I want to redirect all (old) visitors to folder1

RewriteEngine on
RewriteCond %{REQUEST_URI}!^/folder2/
RewriteRule (.*) domain.ext/folder1/$1 [R=301,L]

gives a 500 error

Any suggestions what could be amiss would be deeply appreciated

I fixed it - solution below

RewriteCond %{HTTP_HOST} ^www.domain.ext$
RewriteCond %{REQUEST_URI} !(folder2)
RewriteRule ^(.*) https://www.domain.ext/folder1/$1 [L,R,NC]

@dineshsharma1991

This comment has been minimized.

dineshsharma1991 commented Jan 1, 2018

Hi..
I am using this code for redirection
This will redirect a subdomain to another domain
RewriteEngine On
RewriteCond %{HTTP_HOST} ^blog.example.com$ [NC]
RewriteRule ^(.*) https://www.example.com/blog/ [L,R]
#This code is working if I entered https://blog.example.com/ But when I enter in URL https://blog.example.com/xyz
It show a 500 internal server error Please help me

@SerenHev

This comment has been minimized.

SerenHev commented Jan 9, 2018

Hi,

I am using wordpress and I have over a thousand html urls which I will have to redirect. Considering the fact that theses urls are hosted outside on a different server( domain) and that the new ones will be hosted on servers is it possible to have a htacces redirect and if so could someone please help me? ( the id is of course a variable)

http://www.oldserver.com/?type=pdf&id=id123 ---> http://www.mydomain.com/pdf/id123.pdf

Any help would be much appreciated.

@conqr2

This comment has been minimized.

conqr2 commented Jan 21, 2018

Hi,
I want to create a error redirect with the error path.
For Example:
https://example.com/thisdoesnotexist -> https://example.com/error?path=thisdoesnotexist
I would appreciate help.

@llavillaccama

This comment has been minimized.

llavillaccama commented Jan 24, 2018

Hi,
How can I achieve this:

domain1.com/example1 -> domain2.com/example1
domain1.com/example2/test -> domain2.com/example2/test
domain1.com/example3 -> domain2.com/example3
.
.
.
Thank you

@Stu1815

This comment has been minimized.

Stu1815 commented Jan 26, 2018

Hi I would like to deny direct access to files in an image folder and redirect the "curious" to a specific page.

Let's imagine the image folder is located at the root : http://domain.tld/images
And someone trys to open : http://domain.tld/images/mylogo.png
Whilst still displaying my logo on the page I'd like to redirect those who open directly the image (or video etc.) to the page : http://domain.tld/you_are_too_curious.html

Can anyone tell me what I should put in the .htaccess file please ?

@dws-arjun

This comment has been minimized.

dws-arjun commented Jan 29, 2018

For example

Old URL : https://www.example.com/first/second/third/FILE_NAME

New URL : https://www.newdomain/new_path/FILE_NAME

So what i want is that wherever Old URL is found in the page just replace it with New URL except its FILE_NAME

Tried :
RewriteCond %{REQUEST_URI} ^/templates/applications/default/themes/default/$
RewriteRule ^(.*)$ https://cdn.tracker-files.com/tracker-cdn/ [R=301,L]
but its not working.

Live example :

my old url is
https://www.tracker.com/templates/applications/default/themes/default/logo.png

new URL should be
https://cdn.tracker-files.com/tracker-cdn/logo.png

except file name whole url need to be changed (just like string replace function)

@davidensor

This comment has been minimized.

davidensor commented Feb 5, 2018

I'm trying to figure out how to lose trailing slashes only for URLs with parameters. Here's my use-case:

  1. Marketing campaign uses: campaignsite.com
  2. Visitors are redirected (in AWS) to our main website: mainsite.com/gb/sub-dir/?param1=a&utm_campaign=yup

When the domain is visited, the Wordpress web server is redirecting the browser to: mainsite.com/gb/page-name/?param1=a&utm_campaign=yup/ which ALMOST works, except that the last parameter is getting an extra slash at the end of it.

I'm using a fairly typical WP htaccess file:
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

Any thoughts? Sorry if I overlooked an answer within the actual post, but it seems like this differs from what I saw in the content when I scanned for "param".

Thanks,
Dave

@dkvadratu

This comment has been minimized.

dkvadratu commented Feb 28, 2018

@davidensor try to change permalink structure by removing / (slash) from the end of custom links structure ;)

@shashankbhatt47

This comment has been minimized.

shashankbhatt47 commented Mar 2, 2018

my website is http://www.dailyarts.in/. i Changed permalink url to new structure. Now i am getting 404 error in my posts in search engines results.
Please tell me solution as soon as possible
This was my old url-

You can go to http://www.dailyarts.in/2017/10/21/whatsapp-plus-apk-latest-version-download/ to check 404 error

But now this is new url- http://www.dailyarts.in/whatsapp-plus-apk-latest-version-download/
Now i am seeing 404 error on my old url, Can anyone tell me how to fix this i wanna redirect my old url to new url. I have total 250 old urls in which i am seeing 404 errors. And i wanna redirect them to new changed url. Please suggest me how to fix using .htaccess? Thank you.

@CallMeKlep

This comment has been minimized.

CallMeKlep commented Mar 14, 2018

I'm working on some htaccess redirects for a few stray pages and have come across a few different varieties of 301s that are confusing me a bit....
Most sources (including the example above) suggest Redirect 301 /pageA.html http://www.site.com/pageB.html or using some combination of RewriteRule + RewriteCond + RegEx.

I've also found examples of:
RedirectPermanent /pageA.html http://www.site.com/pageB.html.

I'm confused because our current htaccess file has quite a few (working) redirects that look like this:
Redirect permanent /pageA.html http://www.site.com/pageB.html
This syntax seems to work, but I'm yet to find another Redirect permanent in the wild, only examples of Redirect 301 or RedirectPermanent.

Is there any difference between these? Would I benefit at all from replacing Redirect permanent with Redirect 301?

@ghost

This comment has been minimized.

ghost commented Apr 13, 2018

Can you help me in redirecting URL this way in http config ?
In browser --> http://appserver/pod1/app1 will be redirected to http://appsserver/app1

@arunalagu73

This comment has been minimized.

arunalagu73 commented Apr 17, 2018

Please could you help me to write a rule to redirect when "%" sign is present after digits(in this example 75).

http://internal.www2.test.com/fr/be/images/products/content-75%-ss-ppr__01234_sk621755_s4.jpg -->400 Bad Request The request could not be understood by server due to malformed syntax.
Where as my rewrite rule works fine for the same url without "%" after 75.
http://internal.www2.test.com/fr/be/images/products/content-75-ss-ppr__01234_sk621755_s4.jpg -->http://internal.www2.image.com/be/fr/images/products/content-75-ss-ppr__01234_sk621755_s4.jpg

@sirlouis

This comment has been minimized.

sirlouis commented Apr 30, 2018

@ScottPhillips
when the url bar is saying:
http://example.com/games/arcade/game1
how do i load content from:
http://example.com/games/arcade/game1/v0.6 without changing url bar?
i want to load all content from the /v0.6 without performing a url redirect

@moviezclub

This comment has been minimized.

moviezclub commented May 14, 2018

How to redirect from a title into that search/title ?

www.example.com/title/ -> www.example.com/search/title/

@shaikarif99

This comment has been minimized.

shaikarif99 commented May 14, 2018

hi ,

i want my website redirect from http to https ( only blog folder)

example:- www.mysite.com/india/blog/
i want only to redirect this to https , i have tried out so many rules, but the thing is global website is www.mysite.com when i tried to open this website it is redirecting to www.mysite.com/india/blog.

can any one tell me how to redirect only blog subfolder.

www.mysite.com - global website
www.mysite.com/india/ - another folder
www.mysite.com/india/blog- blog folder

in which htaccess folder i need to update the rule & which particular rule should update, ?

Thanks in advance

@imjaypatel

This comment has been minimized.

imjaypatel commented May 14, 2018

Hello, Following is my sub directory .htaccess rules. Its no longer work.

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?file=$1 [L,QSA]
</IfModule>

Basically URL
https://website.com/subdirectory/a_tag

will result in
https://website.com/subdirectory/index.php?file=a_tag

Why its not work. Please let me know. Thanks

@slincke

This comment has been minimized.

slincke commented May 17, 2018

Hi, I'm building a site that I'd like to allow user to enter using http://www.domain.com/randomstring. I'd like to pick up the 'randomstring' parameter in my index.php file and use its value in the page returned - a bit like bit.ly/123456. However, a 404 error is returned to the client. I added "ErrorDocument 404 /index.php" to .htaccess and that allows this functionality to work, but I'm concerned this approach will hurt SEO. Anyone have advice about how to use a RewriteCond and RewriteRule to handle this better? Thx.

@chrisjnr

This comment has been minimized.

chrisjnr commented May 18, 2018

This saved me a lot of time, Thanks and keep it up

@taishi06

This comment has been minimized.

taishi06 commented May 22, 2018

Hi, I'm trying to redirect my old URL which is

https://mysite.com/blog/1/

to

https://mysite.com/blog?page=1

Please help, thanks!

@JagtapGaurav

This comment has been minimized.

JagtapGaurav commented May 29, 2018

Hello ScottPhillips,

would u please help me to redirect some fake urls which are in subfolders that doesn't exist...,
i wanted to redirect all the subfolder links to the index page that is main domain name...

need a simple solution bcz its 1.25 lakhs url .. which does not exist but crawls by google ...
needs to redirect it to the homepage

-Thanks!

@trinadhv

This comment has been minimized.

trinadhv commented May 30, 2018

Hi @JagtapGaurav

Try this

RedirectMatch 301 ^sub-directory/.*$ http://yoursite.com

@jestech

This comment has been minimized.

jestech commented Jun 2, 2018

Hi, I'm trying to get this done but can't find the right solution anywhere over the internet.
I want to redirect http://careers.domain.com to http://domain.com/hr/careers but keep http://careers.domain.com displayed on the browser address bar.

@lecoqdigital

This comment has been minimized.

lecoqdigital commented Jun 5, 2018

Hello, I am not a dev and not sure how to achieve the following:

Current URL: https://mysite.com/listing-dashboard-page/?action=edit&job_id=3775
Desired URL: https://mysite.com/mon-compte/my-listings/?action=edit&job_id=3775.

How can I achieve this?

Thanks,
Antoine

@ghost

This comment has been minimized.

ghost commented Jun 8, 2018

Hello, Please how do i archive the following.

I want to redirect http://mysite.com/oldfolder/oldfolder/index.php?email='.$email to another subfolder in the same domain.. http://mysite.com/newfolder/index.php?email='.$email

Thanks
Mark

@danmillercoding

This comment has been minimized.

danmillercoding commented Jun 15, 2018

Original URL:
http://www.example.com/old-page/item/

Desired destination URL:
http://www.example.com/new-page/item/

.htaccess syntax:
RewriteEngine On
RewriteRule ^/?old-page/(.*)$ /new-page/$1 [R=301,L]

@ajaynamdev

This comment has been minimized.

@boionfire81

This comment has been minimized.

boionfire81 commented Jun 29, 2018

Using Godaddy how can I achieve these 3 rewrites?
Move all www to non www
Move all http to https
remove the .php|.html|.htm

I can not seem to get these 3 right. I keep getting redirects are to many or unable to locate the file when the extension has been enter.

@dsvinfo

This comment has been minimized.

dsvinfo commented Jul 7, 2018

I have written code in codeIgniter and have set base url like https://example.com/ and suppose I have a button "View Profile" with href link https://example.com/profile/view but when I click on this button url must be change and url should look like https://example.com/new/profile/view but code written in profile controller should be treat like before.
What can I do ?

@vkoori

This comment has been minimized.

vkoori commented Jul 8, 2018

thanks man. great document

@lazycipher

This comment has been minimized.

lazycipher commented Jul 9, 2018

Hey ,

I want to redirect
example.com/?example
to
example.com/file.php?var=example

Is there any way to do that ?

@priyachauhan007

This comment has been minimized.

@priyachauhan007

This comment has been minimized.

@Lzr0

This comment has been minimized.

Lzr0 commented Jul 20, 2018

Hi,
I want to redirect entire http site with its subdomains to https with the same domain, same structure and same sub-domains. Is there a way of modifying Redirect 301 / http://www.domain.com/
so that it would also include sub-domains redirect (like from http://anysubdomain.domainname.com to https://anysubdomain.domainname.com ) or I need to write a redirect line for each subdomain separately?

@bagynathpg

This comment has been minimized.

bagynathpg commented Jul 31, 2018

How to redirect domain.com/index.php to domain.com

@moti-safer

This comment has been minimized.

moti-safer commented Aug 7, 2018

How can I redirect all pages except home page to /sub-directory?

@naijadailyfeed

This comment has been minimized.

naijadailyfeed commented Sep 24, 2018

Perfect Just what i need
Read also: Latest entertainment news in nigeria

@trishawebs

This comment has been minimized.

trishawebs commented Oct 22, 2018

Thank you so much for this, it solved a 500 error that I kept generating when I had made a mistake in setting up my redirects.

@trf000

This comment has been minimized.

trf000 commented Oct 25, 2018

How about
https://www.example.com/activities/pagesmith/6
https://www.example.com/studentlife/pagesmith/6

I seem to be able to redirect the activities dir to the studentlife dir. the word pagesmith is part or the url re-writing my CMS uses. I just need to redirect the initial directory.

@ansulsahu07

This comment has been minimized.

ansulsahu07 commented Oct 31, 2018

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