Create a gist now

Instantly share code, notes, and snippets.

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]

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

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 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

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

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

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

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

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

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

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?

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/

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.....

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.

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

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

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

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

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

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

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!

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 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 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 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

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.

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?

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.

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

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

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!

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.

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?

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 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 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 !

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 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

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? :)

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 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

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 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.

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?

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 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 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 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???

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.

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 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 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 commented Oct 25, 2016

Excellent piece of script set

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 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 ??

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.

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

Try adding (.*) at the end.

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?

chancegehrke 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]

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 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

Thanks for this! Huge help!

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 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/

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.

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

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 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

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 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 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!

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 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.

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

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

thanks in advance

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

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?

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

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

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