Redirect directory to a subdomain - .htaccess

I have my domain pointed to a Rails app in Heroku, so for example, when you wanted to access some video, you would have an URL such as:
http://codigofacilito.com/video/W53XHWkbz34
We need to change that app to a subdomain, so the updated version would be:
http://videos.codigofacilito.com/video/W53XHWkbz34
What I want to know is:
Is there a way to redirect people to the new url with the subdomain videos by using the .htaccess file.

If you need this rule to only be applied to the video route, then give the following a try:
In your document root's .htaccess file, insert the following rule:
RewriteRule ^(video/.*)$ http://videos.codigofacilito.com/$1 [R=301,L,NC]

This works for me
RedirectMatch 301 ^/xxx/(.*)$ http://xxx.domain.com/$1

Using mod_alias:
Redirect permanent /video http://videos.codigofacilito.com/video
The keyword permanent causes Apache to send an HTTP status of 301 Moved Permanently instead of 302 Found.

Related

How do I redirect a web URL using .htaccess

I want to redirect users who enter this website URL:
http://www.myWebsite.com/bananas
to:
http://www.myWebsite.com/fruits/bananas
I cant test it because I'm sending this to somebody.
I have these but I don't know for sure which one works:
RedirectMatch 301 http://www.myWebsite.com/bananas(.*) http://www.myWebsite.com/food/bananas $1
Options +FollowSymlinks
RewriteEngine on
rewriterule ^bananas(.*)$ http://www.myWebsite.com/food/bananas $1 [r=301,nc]
Please specify if you want to redirect or rewrite. The rules you are using serve different purposes and you used both in your example.
Redirect: Actually load a different site when entering the url (end up at url and content of /fruits/bananas)
Rewrite: Url stays the same but server provides rewritten content (url stays at /bananas, but show /fruits/bananas content)
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html
Also it is not clear if you only want one single directory to be redirected or all files that are contained in that directory.
Checkout this as a guide: http://www.htaccessredirect.net/
I believe you are looking for
Redirect 301 /bananas http://www.myWebsite.com/fruits/bananas
The HTTP 301 stands for Moved Permanently.
I haven't tested it, though.

.htaccess redirect from subdirectory to another domains subdirectory accordingly

I am trying to make a redirect from my primary domain to an secondary domain, but only if the primary domain's request is to a sub directory.
The sub directory I want to redirect from is FTP, so if the user makes the following request:
http://www.site1.com/FTP/free/50b694124bd63/SaMple+PicTure.PnG
it would be transformed to
http://www.site2.com/FTP/free/50b694124bd63/SaMple+PicTure.PnG
but if the user makes a request that does not involve the FTP folder, the user will not be redirected. Like so:
http://www.site1.com or http://www.site1.com/somethingelse/
I am, however; a bit lost when it comes to making .htaccess files. What I have tried to do so far is:
# Redirect users
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^ftp(.*)$ http://site2.com/FTP/$1 [L,R=301]
</IfModule>
Any directions or samples would be great :)
No need to use the rewrite engine for simple redirects. I think you just want to use the Redirect directive:
Redirect /FTP http://www.site2.com/FTP
By default, this will result in a "temporary" redirect response (HTTP status 302). If you're sure the URL of the second site will never change, you can cause a "permanent" redirect response (HTTP status 301) by adding the permanent argument:
Redirect permanent /FTP http://www.site2.com/FTP
Also, note that the path of URLs is case-sensitive. If you want http://www.site1.com/ftp to also redirect, you will either need to add a rule with the lowercase path,
Redirect /ftp http://www.site2.com/FTP
or use mod_speling.

How can I set the RewriteModule in .htaccess?

I will present a to the point example.
I have a domain name as: www.abc.com
And another domain name as: www.123.com
Now i want to write a rewritemodule in .htaccess for the following case:
If i request a url like: www.123.com/xyz
It will redirect my request to www.abc.com/track/index.php?ext=xyz
Also please tell me on which directory i should keep that .htaccess file.
Thanks.
In the root folder of www.123.com, you would create an htaccess file with the following line:
RedirectMatch 301 (.*) www.abc.com/track/index.php?ext=$1
Since you are doing an external redirect, it is not necessary to use mod_rewrite.

redirect ALL urls from old site to index.php on new one with .htaccess?

A couple questions, simply:
Is the .htaccess file generally stored in the public_html directory? I think so, no?
If I do not find such file, can I simply create it and upload it with FTP?
3 (most importantly). What is the code I need to redirect ALL URLS to ONE new URL, namely, http://www.newsite.com
Is it nothing more than Redirect 301 / http://www.newsite.com/?
Thanks
Is it nothing more than Redirect 301 / http://www.newsite.com/?
Correct, it is the only thing you need. It will redirect anything starting with / to the appropriate place in http://www.newsite.com/. Example:
You go to http://oldsite.com/some/path/to/file.php, you'll get redirected to http://www.newsite.com/some/path/to/file.php.
If you want everything to go simply to the document root of the new site, you can use a RedirectMatch instead:
RedirectMatch 301 .* http://www.newsite.com/
So if you go to http://oldsite.com/some/path/to/file.php, you'll get redirected to http://www.newsite.com/
Not all apache installations come with mod_rewrite installed, if it's not installed you'll get a 500 server error if you attempt to use the rewrite engine. However, mod_alias is usually always installed.
Question 1: Whether you can just upload .htaccess to public_html depends on the web host, but that will likely work.
Question 2: I would set up the redirect like this:
RewriteEngine On
RewriteRule ^(.*) http://www.newsite.com/ [R=301,L]

complex htaccess rewrite

Before using word press for our new website we were using following urls...
http://www.domain.com/web-services
http://www.domain.com/seo-services (about 100 urls)
Now new url would be
http://www.domain.com/np/web-services
So we would like to 301 redirect all old pages to new pages, we could simple use following htaccess code...
Redirect 301 /web-services http://www.domain.com/np/web-services
But that would make htaccess file too large, so is there any way to redirect all pages to new pages.
thanks.
Enable mod_rewrite on your apache server, then put this inside your .htaccess file:
RewriteEngine On
RewriteRule ^/web-services/(.*)$ /np/web-services/$1 [R=301,L]
RewriteRule ^/seo-services/(.*)$ /np/web-services/$1 [R=301,L]
Any url starting with /web-services or /seo-services will be redirected to /np/web-services.
Or alternatively, you can use mod_alias' RedirectMatch:
RedirectMatch 301 ^/([^\-]+)-([^/]+)/?(.*)?$ /np/$1-$2/$3
So any request that starts with /web-services/ will get redirected with a /np appended to the front:
http://www.example.com/web-services/test1 -> http://www.example.com/np/web-services/test1
http://www.example.com/web-services/test/test2 -> http://www.example.com/np/web-services/test/test2
And the same with seo-services or anything with XXX-XXX.
EDIT:
if i try RedirectMatch 301 ^/([^\-]+)-([^/]+)-([^/]+) /np/$1-$2-$3/ its thorwing redirection error
Try:
RedirectMatch 301 ^/([^/\-]+)-([^/\-]+)-([^/]+) /np/$1-$2-$3/
Because /np/ is being matched against ^/([^\-]+)
You can rewite your domin like as if your domin was open with abc.com then you can permanently redirect it with www.abc.com. By doing this you can make sure that when google spider visit on your site then it can easily find your site. It also helps to increase more traffic on your site. If you have a busieness website then you can use SEO service from a company in Los Angeles going through reviews of best SEO Company in Chicago. Because these are helps to always push up your business growth towards top. Origin : http://www.bestseocompanyreviewss.com.

Resources