I have set up a subsystem in my app:
example.com/index.cfm/subsys:foo/bar
What I want to do is map a subdomain to that subsystem to eliminate the need for the subsystem specification in the PATH
subsys.example.com/index.cfm/foo/bar
We serve our FW1 app through IIS6 currently, but may migrate to Apache, so a solution in either is acceptable.
With Apache's mod_rewrite you can do something like:
RewriteCond %{HTTP_HOST} ^(subsys)\.example\.com
RewriteRule /index.cfm/(.*) /index.cfm/%1:$1
To make it work with multiple subdomains/subsystems, use a pipe-delimited list inside the parentheses:
RewriteCond %{HTTP_HOST} ^(sub1|sub2|sub3)\.example\.com
To make it work for any non-www subdomain, for any domain, use a condition such as:
RewriteCond %{HTTP_HOST} ^((?!www\.)\w+)\.
For IIS6, you would probably need third-party software, such as Helicon Tech's ISAPI Rewrite, which supports mod_rewrite syntax.
Related
For some reason search engines are indexing my addon domains on my hosting. They should not do that.
For example I just found urls like
addondomain/maindomain.com
how to prevent this happening? How did search engines even find my addondomains?
What is the solution here? I tried this
RewriteEngine on
RewriteCond %{HTTP_HOST} ^addondomain\.maindomain\.com
RewriteRule ^(.*)$ http://www\.maindomain\.com [L]
but when I visit the url for example
addondomain/maindomain.com for example nothing happens?
Try to Change in .httaccess file. You can replace your rule with this rule::
RewriteCond %{HTTP_HOST} =shop.domain.abc
RewriteRule ^ http://www.domain.abc/? [R=301,L]
Using %{REQUEST_URI} will cause original URI to be copied in target. Trailing ? in target will strip off any pre-existing query string.
This answer is a further explanation to my comment on your question.
how to prevent this happening? How did search engines even find my
addondomains?
Google can easily find these subdomains on your site. To prevent this from happening, you can set a redirection with a 301 status code to inform Google that it should not index the addon domain. By doing this, Google will update its index as well.
This is a very common scenario with shared hosting and specially when you use CPanel. In Hostgator's support pages, you can see they have mentioned about this behavior.
Addon URL Example
For the primary domain abc.com, if you assign the addon domain 123.com
to the folder "123," the following URLs would be correct:
abc.com/123
123.abc.com
123.com
All three of these paths would access the same directory and show the
same website. For visitors going to 123.com, there is no evidence that
they are being routed through 123.abc.com.
https://support.hostgator.com/articles/cpanel/what-is-an-addon-domain
You can fix this by adding the following to your .httaccess
RewriteEngine On
RewriteCond %{HTTP_HOST} ^addondomain\.maindomain\.com$ [NC]
RewriteRule ^ http://www.maindomain.com [R=301,L]
NC - match in a case-insensitive manner.
R - causes a HTTP redirect to be issued to the browser. When given as
R=301 it will be issued with a 301 status code which is required to
inform Google that their index should be updated accordingly.
L - Causes mod_rewrite to stop processing the rule set. In most
contexts, this means that if the rule matches, no further rules will
be processed.
===========================================================
Edit: Updated to add redirection to all domains, as requested in the comments.
To do this, you can simply check if the hostname is equal to your main domain, and if it's not, redirect it to the main domain.
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.maindomain\.com$ [NC]
RewriteRule ^ http://www.maindomain.com [R=301,L]
Hope it helps :)
I'm making a JavaScript web app running on an Apache 2 server. I'm wondering if it's possible (either with mod_rewrite or some other mod) to make any path you type load the index.html from the root path, but keeping the URL?
For example: "example.com/blah/blegh" will load "example.com/index.html", but the address bar will still have "example.com/blah/blegh". Same if you tried typing "example.com/everything/is/index" would still load "example.com/index.html" and have "example.com/everything/is/index" in the address bar.
A simple answer about any mods I would need to use and which commands might be best would suffice. Though a code example would be very useful since I'm new to regex's and Apache rewriting.
Thank you for your time :)
Note: I'm doing this since I'm using History.js to parse URLs/titles into the address bar and tab titles while navigating (a one-page dynamic site). I'd like to be able to just load up the root index.html with the user's initial URL request and respond to users' actions that way much like a REST server.
Actually, you want to rewrite without redirecting. This requires enabling mod_proxy and mod_rewrite in Apache's httpd.conf.
Then, the rewrite should look like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.html [NC,L,QSA]
Reference:
What exactly does the Multiviews options in .htaccess?
htaccess rewrite without redirect
Apache: RewriteRule Flags
I am trying to redirect http://www.gelda.com/web_pages/food_index.html to http://food.gelda.com/.
I've tried the following:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
Redirect 301 /web_pages/ http://food.gelda.com/
</IfModule>
This didn't work, it redirected to http://food.gelda.com/food_index.html
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} ^gelda.com/web_pages/food_index.html$ [OR]
RewriteCond %{HTTP_HOST} ^www.gelda.com/web_pages/food_index.html$
RewriteRule ^(.*)$ http://food.gelda.com/ [R=301,L]
</IfModule>
This also redirected to http://food.gelda.com/food_index.html
I am not sure what to do in my .htaccess file to make this happen. I need anything in /web_pages/ to go to food.gelda.com.
Two alternatives based on the rewriting module:
You can use the http servers host configuration (preferred) or a dynamic configuration file in the hosts document root folder (so parallel to the /web_pages folder):
RewriteEngine on
RewriteCond %{HTTP_HOST} ^gelda\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.gelda\.com$
RewriteRule ^/?web_pages/ http://food.gelda.com/ [R=301]
Or you use a dynamic configuration file inside the hosts /web_pages folder:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^gelda\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.gelda\.com$
RewriteRule ^ http://food.gelda.com/ [R=301]
In all cases the rewriting module needs to be loaded and activated, obviously. If you decide to use a dynamic configuration file (.htaccess style file), then you need to enable it's interpretation using the AllowOverride directive in the http servers host configuration. Also that file needs to be readable by the server process, obviously.
And a general hint: you should always prefer to place such rules inside the http servers (virtual) host configuration instead of using dynamic configuration files (.htaccess style files). Those files are notoriously error prone, hard to debug and they really slow down the server. They are only supported as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).
I have a webserver and a subdomain. All of my images are stored in /public/images within my site directory for www.mysite.com. However I have a separate site directory for testing beta.mysite.com however on this page with a different git branch all of my images are broken because I did not want to copy all of the images. Is it possible to say for all image requests or for all 404 requests try looking at mysite.com?
I have found an example on another questions
RewriteEngine On
RewriteCond %{HTTP_HOST} ^test.example.com$
RewriteRule ^images/(.*)$ http://example.com/sub_ds/test/images/$1
But since I am rather new to mod_rewrite im not sure what is going on or how to manipulate it to work for me.
You can use this rule in root .htaccess of beta subdomain:
RewriteEngine On
RewriteCond %{HTTP_HOST} =beta.example.com
RewriteRule ^(images/.+)$ http://example.com//public/$1 [L,NC,R=301]
I'm using AltoRouter: (http://altorouter.com/) and I modified .htaccess as suggested in the instalation to:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
This is so that index.php can handle all the requests. My problem is that I am using addon domains in cpanel and I am having internal server errors when I try to access one of the domains associated with the addon domain.
Example:
My main domain is mainsite.com.
Then I have several sites:
site1.com that cpanel automatically associates with site1.mainsite.com and creates a folder mainsite.com/site1.com. So if I access site1.com I would see in browser site1.com but the content delivered would be the one inside the mainsite.com/site.com folder.
This works if I don't use the .htaccess rule but I need it for routing. If I have that rule I get internal server errors everytime I access site1.com (I assume that it's a conflict between cpanel rules and .htaccess).
How can I modify the rule so that it only affects maindomain and not subdomains? I am assuming that by doing this there would be no conflict and my problem would be solved.
I am really bad at .htaccess and regex but I am willing to learn if needed. I would still appreciate if you could point me to the right direction. (both in the idea and in good websites that can help me understanding this)
How can I modify the rule so that it only affects maindomain and not subdomains?
You can add a new condition based on host name:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(?:www\.)?mainsite\.com$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]