Rewriting example.com/folder/path to example2.example.com/path - mod-rewrite

Actually the thing is that i'm having a sub domain (example.domain.com) which is redirected from other domain of a folder (www.domain/folder) . but need the rewrite rule for my sub domain which shows the url links for the main domain ie., www.domain/folder/path
i need to get as example.domain.com/path. Instead of getting the main domain path i need to expose the URL with sub domain path.

As far as I can tell, there are two ways to do what you are wanting. Both of them require significant extra overhead. Both are also likely to require example.domain.com to lie about who it is.
I wouldn't recommend either if you can avoid it, but.
Method #1
Set up a transparent proxy on www.domain.com/folder to show the contents from example.domain.com. If I recall correctly, this can be done with mod_proxy, but I don't remember how specifically.
Method #2
Set up a rewrite rule on www.domain.com/folder to redirect to example.domain.com. Then set up example.domain.com to either lie about who and where it is, or fix all links in pages on example.domain.com to explicitly go to http://www.domain.com/folder.
In the root .htaccess file on www.domain.com: (to redirect to the subdomain)
RewriteRule ^folder/(.*) http://example.domain.com/$1 [R, L]

Actually the subdomain is created from godaddy account and the maindomain/folder is in other hosting server... masking can be done in top address bar but when i hover through links the actual URL path is displayed in lower left corner of the browser....
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{THE_REQUEST} {HTTP_HOST}[a-zA-Z0-9.-]mydomain/folder/(.)
RewriteRule ^/folder/(.*)$ http://abc.example.in/$1 [L,R=301]
Some one has mailed me the above rewrite rule but still the problem persists...
I have been working on this issue from couple of days and i came to conclusion that
1)From godaddy account i have created a subdomain and forwarded with masking to the actual IP address of the virtual host server, but here comes the problem...
i could not forward to the (domainname/foder) rather i can do it for domainname
So i stuck up here for the solution
If u find a solution i would be considered them as a GENIUS......

Related

Redirecting from one domain to another with mod_rewrite

I've set up a site for someone that has a URL like:
www.flowers-oakville.com.
But they'd also like www.flowersoakville.com to land on the page.
The question now is, what is the best way to redirect from www.flowesoakville.com to www.flowers-oakville.com. I don't want the user's browser to show the redirection by showing the new URL in the address bar so I think Apache's Redirect command is not the solution. Plus, the Apache Redirect would take an extra trip to the browser and back that I'd like to avoid. So I think the solution needs to be a mod_rewrite, which as I understand it, does everything within the server so the round trip is avoided and the user's address bar is unchanged.
But after reading through a few mod_rewrite tutorials, it seems that mod_rewrite is mainly for redirecting files, not an entire website. Is there a simple way to do this?
Thanks for any help.
I would do this at the domain level and ensure you are using relative links or an environment variable for the hostname in the website.
Add www.flowersoakville.com as a CNAME record pointing to www.flowers-oakville.com.
This will then serve the same website, but retain the domain name as the user entered it, unless you have explicitly linked the actual domain in a link somewhere in the site.
If mode_proxy
is enabled on your server, you can use mod_rewrite (the following code) in your .htaccess file to redirect a domain to another domain without changing url in the address bar.
Try adding this to www.flowersoakville.com/.htaccess file :
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?flowersoakville\.com$ [NC]
RewriteRule ^ http://www.flowers-oakville.com%{REQUEST_URI} [L,NE,P]
Note : The example above will not work if proxy module is not enabled on your server.
I wanted to pass on my experience trying to use Dwev's answer. It turns out that the DNS Manager running in my virtual server (I'm using eApps as my hosting provider) does not support "domain based redirection." That is, the left side of a CNAME record has to be in that domain. So when trying to build a CNAME record in the flowers-oakville.com record that points to flowers-oakville.com, the left side has to be xxx.flowers-oakville.com where the xxx might be something like www. I can't get the left side to be flowersoakville.com, even though flowersoakville.com is one of the domains my server is listening for.

Multiple URLs for magento store?

Quick question-
Noticed a problem on my Magento 1.7. Consider the site http://www.seacadetshipsstore.com/magento/. This site has a sub-store that's /magento/gearlocker/. The two should be isolated - if you go to /magento/gearlocker/, you shouldn't interact with the generic store at /magento/ at all.
Here's the problem: the store's base URL is set explicitly to http://www.seacadetshipsstore.com/magento/gearlocker/. When users navigate to http://seacadetshipsstore.com/magento/gearlocker/ (no www), they get redirected to http://www.seacadetshipsstore.com/magento/.
My question is this: if a user navigates to the gearlocker site without www, is there a way to set a second store URL to prevent a redirect? Or would it be easier to control that redirect back to /magento/gearlocker/, instead of /magento/? Any thoughts, solutions, or references would be greatly appreciated. Thanks!
See my comments above. Thanks #CodeMoose
RewriteEngine On
RewriteCond %{HTTP_HOST} ^seacadetshipsstore.com
RewriteRule (.*) http://http://www.seacadetshipsstore.com/magento/$1 [R=301,L]
If I remember correctly I believe duplicate urls across multiple stores are not possible without one of the urls being auto incremented with a -1 -2 etc. Please try modifying one of the url keys and let me know what happens.

Multiple index files in different folders?

I just figured out that if I have multiple folders in my website such as logout and login I can then have a log out/in page within the folders called index.php
Now when someone goes to project.com/login/ it will load up the index.php file in that folder and the url will look nice.
Is there any problem in doing this?
As Candy Pointed out it is better to do this with url rewrite rather heeps of folders and index files. I went and looked it up and you can do a lot of cool things.
for the basics:
http://www.addedbytes.com/for-beginners/url-rewriting-for-beginners/
http://www.yourhtmlsource.com/sitemanagement/urlrewriting.html
Instead of creating many folders which would make the site confusing (for the developer) and having numerous index.php files which would also get confusing if you were editing more than one at a time, you can use the apache mod_rewrite module which lets you transparently (the url in the address bar stays the same) redirect one URL to another. You could use this to clean up messy url's and have /login/ instead of /login/login.php or /user/1335591/ or even /user/'username'/ rather than an ugly url which is hard to remember like the following: /user/user.php?user=1335591
to start first put RewriteEngine on in your .htaccess file to turn it on
redirects are then written in the .htaccess file in sequence
Below is an example:
RewriteRule ^products/([0-9][0-9])$ /products/$1/ [R]
RewriteRule ^products/([0-9][0-9])/$ /productinfo.php?prodID=$1
If the user types in products/12 the first rule will append a trailing slash to it. The second rule will transparently redirect this URL to productinfo.php?prodID=12

Wrong redirection to old site after Magento's duplication

I’ve got this problem: Magento redirection problem after moving
I changed local xml, deleted cache, changed secure and unsecure link, everything… It doesnt’ work. The only difference is that I duplicated my installation on the same server and I changed subdirectory’s name for the second installation. But I tried also on another server and is almost the same, except for the fact that it keeps linking me back to Google, and not to old domain.
I noticed that if, on the other server, I don’t change subdirectory’s name everything works (and I don’t understand why) but I want on the same server 2 identical installation with 2 identical databases. How can I? What’s the problem? How can I avoid this wrong redirect?
Magento relies heavily on caching. I've noticed in the past I've had to clear my browser internet cache before the redirects updated.
Also if you cloned/duplicated the code & database, its likely you will have the old URL's in the rewrite module. Have you tried reloading all the indexes after moving and changing the URL's in the magento configuration?
Worst case you may have to change the URL in the core_config_data table in the database.
There is no reindex required for base_url to be taken in account.
Only cleaning cache is required. Are you sure you did it well ?
What cache system are you using ?
What did you changed in your local.xml for this ?
Are you sure you didn't left old information in a local.bak.xml for example ? Magento reads every xml file in /app/etc
I have encountered this when moving, and it ended up being that my .htaccess file still had an old rewrite rule pointing to the old domain. In case someone else has this issue for which the other suggestions to not apply, look for something like this:
RewriteCond %{HTTP_HOST} !^www\.localhost\.com$ [NC]
RewriteRule ^(.*)$ http://www.localhost.com/$1 [R=301,L]
and make sure obviously that the localhost.com matches your domain (the above simply redirects with a 301 permanent redirect rewrite any request that does not begin with www.localhost.com to http://www.localhost.com/ (such as the non-www localhost.com)

More Mod_rewrite problems

Ok, have a client that has existing links coming in from searchmarketing. I am in process of migrating the program from Cold Fusion to PHP.
RewriteEngine on
RewriteRule ^cat_ap~([^~]+)~(.*)\.htm$ /urban/cat_ap.php?$1=$2 [R]
Currently I have a URL structure:
http://www.test.com/urban/cat_ap~nid~5964.htm
which the above rewrite rule changes to
http://www.test.com/urban/cat_ap.php?nid=5964
Now I want to be able to get the variables out of the query string but maintain the url in the browser to the original http://www.test.com/urban/cat_ap~nid~5964.htm but still have it go to the PHP page.
So that when someone goes to http://www.test.com/urban/cat_ap~nid~5964.htm it actually goes to http://www.test.com/urban/cat_ap.php?nid=5964 but still shows http://www.test.com/urban/cat_ap~nid~5964.htm.
Any ideas on how to do this?
Thanks
Mike
You are already doing this on this line (but change the R flag to L):
RewriteRule ^/urban/cat_ap~([^~]+)~(.*).htm$ /urban/cat_ap.php?$1=$2 [L]
The URL that the user hits will still show as the .htm version while the server processes it as the .php
The R flag explicitly induces an external redirect. So just remove the R flag.
I think you'll need to set up reverse proxying to achieve the desired behaviour, and use the P flag with your rewrite rules. I've used a site with this sort of configuration before, so can say that it works, but I'm afraid I've never configured it myself :-(
A good first step at least would be to install mod_proxy and get it loaded and running. The mod_rewrite cookbook page on the P flag has a small amount of detail on proxying RewriteRules, and links through to the ProxyPassReverse directive documentation at apache.org.

Resources