Redirect custom URLs via htaccess - .htaccess

I have my own domain:
http://cesarferreira.com
and I wanna make
http://cesarferreira.com/github
point to
https://github.com/cesarferreira
Without having to make a /github/ folder with an index.html with a redirect for each page I own (facebook, twitter, pinterest, etc)
Is there a way like for example htaccess catchig *.com/github and pointing to a given static url?
Thanks a lot

If your document root serves -
http://cesarferreira.com
you can put a redirect in .htaccess like -
Redirect /github https://github.com/cesarferreira

Take a look at URL rewriter 'http://httpd.apache.org/docs/2.0/misc/rewriteguide.html'. That should be able to do everything you want and more.
As long as it is enabled in apache then you can use it in .htaccess files also.

You can use mod_alias:
Redirect 301 /github https://github.com/cesarferreira
Or if you only want github to point only to the folder:
RedirectMatch 301 ^/github https://github.com/cesarferreira
You can put that in the htaccess file of your document root.

Related

Setup htaccess not to redirect when hit from main site

I'm not even sure how to ask this correctly so if I am duplicating a question I apologize. How do I use my htaccess file to only redirect when someone is coming in on something other than the main site name?
Example:
I do not want redirect on www.examplesite.com
I do want to redirect on www.examplesite.com/page.php
I think this is what you're looking for:
Perform a redirection with .htaccess
The easiest and simplest way of redirecting with .htaccess is to use the Apache module mod_alias and its command Redirect. Here’s is how to make a temporary redirection with htaccess:
Redirect /page.php http://www.examplesite.com/go_to_this_page.php
Is this along the lines of what you're asking? If so, I hope it can help.
The Structure : redirect accessed-file URL-to-go-to
The code :
Redirect 301 / http://www.examplesite.com/page.php

Need redirect old url to new friendly url

a need redirect
http://www.mysite.com/product.php?id_product=216
to
http://www.mysite.com/category/newProduct.html
I try to add a line in htacces
redirect 301 /product.php?id_product=216 http://www.mysite.com/category/newProduct.html
but dont work.
If I add
Redirect /product.php http://www.mysite.com/category/newProduct.html
All links like
http://www.mysite.com/product.php
http://www.mysite.com/product.php?id_product=216
http://www.mysite.com/product.php?id_product=219
Go to homepage http://www.mysite.com/
Any idea. THX
Check the following:
Make sure your file is called .htaccess, not htaccess as you say above.
If you're using FTP to transfer it to the server, use ASCII rather than binary transfer mode.
Make sure the .htaccess file is in a directory where the Apache AllowOverride directory option is on if you're using apache web server.

Which .htaccess file should I be using for 301 redirects?

This is one of those super-simple questions that I can't seem to google an answer for, so apologies in advance.
When I ftp into my (shared) server, I have a file structure like this:
Root (/)
/public_html
/newdomain.com
I had an old website that lived in /public_html, it had heaps of content and excellent SEO. We changed our name and our domain (which lives in /newdomain.com, a folder inside /public_html), and set 301 redirects from all the old content to the new website.
I tried doing this myself, but it didn't work at all, so I got my host's techsupport to do it for me. There are several .htaccess files on my server though, and I don't know which ones are actually effective and which aren't.
Root has its own .htaccess file
public_html has its own .htaccess file
/newdomain.com DOESN'T have its own .htaccess file
Redirection 1 (currently is in both root and public_html's .htaccess files, and works)
I want to redirect http://olddomain.com/whatever -> http://newdomain.com/whatever (I've currently got each individual page doing its own separate 301 versus a single rule doing this). Achieved with Redirect 301 /article-name-here/ http://www.newsite.com/article-name-here/
Redirection 2 (currently is in both root and public_html's .htaccess files, and doesn't work).
I also want to do some internal redirections of http://newdomain.com/oldpage.html -> http://newdomain.com/newpage.html. I've tried redirection public_html's .htaccess file like so:
Redirect 301 http://newsite.com/badpage.html http://newsite.com/goodpage.html
But it's not working. Do I need to set up a new .htaccess in the newsite.com folder on my server? Or am I just completely missing the mark here?
Redirection 1
To redirect everything, just remove the article name:
Redirect 301 / http://www.newsite.com/
Or if you don't want to redirect the root (i.e. requests for /), then:
RedirectMatch 301 ^/(.+)$ http://www.newsite.com/$1
Redirection 2
If the /newdomain directory is the document root for http://newdomain.com/, then you'll need to create a new htaccess file there and include:
Redirect 301 /badpage.html /goodpage.html

Redirect with HTACCESS without any index files

I have a domain, but it has no files on the webhost. I want to know if it's possible to do the following with only a .htaccess on my webhost.
But what I want to use this basically for is that I want to redirect my web root http://(www.)mydomain.net to http://domain2.net. And I want http://(www.)mydomain.com/1/ redirect to domain3.net.
Can anybody help me out?
Thanks a lot!
Use the htaccess Redirect line..
i think it would be this (i didn't check to verify it works... but fiddle with it):
Redirect http://mydomain.net http://domain2.net
Redirect http://mydomain.net/1 http://domain3.net
http://kb.mediatemple.net/questions/242/How+do+I+redirect+my+site+using+a+.htaccess+file%3F
You can do this with s simple 301 directive mixed with directories:
I would point mydomain1.com to ip xxx.xxx.xxx.xxx/mydomain1 and then in the htaccess in that directory:
Redirect 301 / http://domain1.net/
Then you can repeat the same for site 2: point site to to ip xxx.xxx.xxx.xxx/mydomain2 and in the htaccess for that directory
Redirect 301 / http://domain2.net/

How can I use .htaccess to redirect a folder on my website to a folder on another website?

I'm trying to have everything in this folder on my website - http://www.mywebsite.com/media/images/* redirect to another website with the same structure i.e. http://www.theotherwebsite.com/XXX/media/images/* using .htaccess
Even simpler, it can be accomplished by Redirect alone, no need to use Rewrite.
Redirect permanent /media/images http://foobar.com/new/location
Okay... managed to figure this one out...
RewriteRule ^media/images/(.*)$ http://www.theotherwbsite.com/XXX/media/images/$1 [L]

Resources