How can I set the RewriteModule in .htaccess? - .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.

Related

htaccess - redirect parent folder to file within parent folder

I'm attempting to redirect the user to a file within a folder if the user types the folder's address as a URL.
For example:
https://www.example.com/shop
should redirect to:
https://www.example.com/shop/en_GB/index.html
I've tried to do it using a htaccess file in the root with the following rule:
Redirect 301 /shop https://www.example.com/shop/en_GB/index.html
but this does not work - it adds the file URL over and over again in the address bar.
Can anyone help? Thanks.
Redirect directive matches any URI pattern that starts with the given string. Hence you're getting a redirect loop.
You should use RedirectMatch directive for this purpose that supports regex and allows you to match precise strings.
RedirectMatch 301 ^/shop/?$ /shop/en_GB/index.html
Make sure to use a new browser for your testing or clear browser cache completely.

url redirection in magento not working with index.php

I want to redirect url in magento. I am using "URL rewrite Management".
We want this path "/index.php?cPath=1" redirect to "baby-prams-strollers.html" this path.
I have entering data this type
Request Path * index.php?cPath=1
Target Path baby-prams-strollers.html
But it will be redirect on homepage. we want to redirect on baby-prams-strollers.html this path. How can we do this? Please advice me.
If we have entered this type of data
Request Path * ?cPath=1
Target Path baby-prams-strollers.html
Now it will be redirected on "baby-prams-strollers.html" this path but url is coming with index.php/baby-prams-strollers.html. Now we don't need index.php in URL. How can we remove index.php in this URL. We have already removed index.php in our all url. but when we redirection of this type url that time it will be added url in index.php.
Thanks in advance.
You need to add to your .htaccess file in your Magento root folder soomething like this:
RedirectMatch 301 /index.php?cPath=1(.*) /baby-prams-strollers.html$1

Redirect directory to a subdomain

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.

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

htaccess folder to subdomain rewrite

How can example.com/blog seamlessly show the content of blog.example.com without a redirect?
Not this:
RewriteRule ^/blog http://blog.example.com [R=301,L]
Thanks.
In order for this to occur, both the domain and subdomain would have to be running from the same directory of files. Then you could just rewrite the /blog path to the same file that the subdomain is using to run. Depending on your permissions, it could be possible to specify a ../ path to the file that it's using if you get the directories right.
However, anytime you specify a full domain path in a rewrite rule, Apache will always redirect the request. You can't get around that.
if example.com/blog and blog.example.com(subdomain) both points to same directory(blog). Then you can directly access the specified path without any redirection.

Resources