I'm running Apache 2.4 and using mod_rewrite to achieve the following - I need to proxy several different internal sites so that they appear to have been hosted on the same server. As an example, the way I'm looking to do this is to have URL's of the form http://myserver/osnews
which will proxy content from www.osnews.com and http://myserver/slashdot which will proxy content from www.slashdot.org. I have the following rewrite-rule defined in my apache conf file:
RewriteCond %{REQUEST_URI} ^/osnews(/?.*) [NC]
RewriteRule ^/osnews(.*) http://www.osnews.com$1 [P]
RewriteCond %{REQUEST_URI} ^/slshdot(/?.*) [NC]
RewriteRule ^/osnews(.*) http://www.slashdot.org$1 [P]
The problem is that this breaks all the stylesheets and images from the proxied site. I think it's because the rewritten URL's are of the form http://myserver/story/28554/Russia_unveils_homegrown_PC_microprocessor_chips instead of http://myserver/osnews/story/28554/Russia_unveils_homegrown_PC_microprocessor_chips
On the contrary, if I try something like this, it works just fine (I don't have the site as part of the original url so http://myserver will just proxy to http://www.osnews.com):
RewriteCond %{HTTP_HOST} ^myserver$ [NC]
RewriteRule ^ http://www.osnews.com%{REQUEST_URI} [P]
So, what I need direction on is how to preserve the URL http://mysite/osnews/some-resource after the proxying returns from http://osnews.com/some-resource
Thanks!
So, I have got this working using mod_proxy instead of mod_rewrite. The configuration I used (within the VirtualHost context) is:
ProxyPass /osnews.com/ http://www.osnews.com/
ProxyHTMLURLMap http://www.osnews.com /osnews.com
#LogLevel debug proxy_html:trace5
<Location /osnews.com/>
ProxyPassReverse /osnews.com/
ProxyHTMLEnable On
ProxyHTMLExtended On
ProxyHTMLURLMap ^/ /osnews.com/ R
ProxyHTMLURLMap ^/css/(.*) /osnews.com/css/$1 Rc
ProxyHTMLURLMap ^/images/(.*) /osnews.com/images/$1 Rc
RequestHeader unset Accept-Encoding
</Location>
One thing to note is that if you're using apache2 on Ubuntu (Lubuntu 15.04 in my case), the config file for mod proxy_html is not provided by default. You need to create it and then enable it using a2enmod proxy_html. This article summarizes it well: http://ckdake.com/content/2008/reverse-proxying-with-apache-and-modproxyhtml.html.
There are still some issues I see where the ProxyHTMLExtended output-filter is not mapping URLS correctly. But I expect to get those ironed out eventually.
Related
I've VPS in OVH and i developped website with j2ee and i associate apache with tomcat using mod_jk.
when i enter url http://ip_of_vps/myapp, i enter to website.
until now it's ok
now i add rewrite for access to website using only ip_of_vps without context (myapp), for this i'm using Rewrite in apache2.config like this :
<virtualhost *:80>
RewriteEngine On
LogLevel alert rewrite:trace6
RewriteRule ^/$ http://ip_of_vps/myapp/ [P,L]
</virtualhost>
And i change All AllowOverride in directory from none to All
when i try to access to http://ip_of_vps, i've apache2 home page.
what i've forgot ?
I'm using ubuntu 14.04 server, apache2, tomcat7.
Off the top of my head, typically you would write
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
ReWriteRule your rule
</IfModule>
so, is mod_rewrite actually loaded?
do you need your RewriteBase to be /myapp/ ?
my suggestion would be to put a .htaccess in your html root directory
with a rule like
RewriteRule ^myapp/(.*)$ $1 [L]
this way you wont need mod_proxy at all
hope this helps
I've just setup an AMP server on OSX 10.9 and have a bizzare problem which is not present on my live hosting server or my old WAMP server.
I want to redirect any URL that doesn't directly map to a file on the server to index.php. I'm using the following .htaccess code
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# prevent loop
RewriteCond %{REQUEST_URI} !index\.php
RewriteRule ^(.*)$ /index.php?/$1 [L]
when I try http://example.com/example there is no problem, but when I introduce another slash, for example, http://example.com/example/
I get the a 404 error The requested URL /example.html/ was not found on this server.
Server version: Apache/2.2.26 (Unix)
Looks like your problem is related to enabling of MultiViews here. Turn it off by using this line on top of your .htaccess:
Options -MultiViews
Option MultiViews is used by Apache's content negotiation module that runs before mod_rewrite and and makes Apache server match extensions of files. So /file can be in URL but it will serve /file.php.
Inside the LAN, we are good to go… folks access our intranet using http:// intranet All links and URLs work just fine and dandy (I removed index.php from links using URL Rewriting).
We are required to give access to the Intranet to certain outside folks.. we are accomplishing this using FTMG, the same way in which Outlook Web Access works.
Now, calls to https:// intranet.domain.org work, but links within the site do not work… for example:
https:// intranet.domain.org works
https:// intranet works
https:// intranet.domain.org/homepage FAILS
https:// intranet.domain.org/index.php/homepage works
https:// intranet/index.php/homepage works
(Disregard space after https://, I received errors for invalid links)
Taking away the 's' from https, and the entire site functions properly.
The dilemma should be clear… implementing the URL Rewriting is not work with https…
How do I make it work?
Note:
my config file =
$config['base_url'] = '';
my .htaccess file =
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Perhaps this will be of some help HTTP/HTTPS, without index.php, using htaccess
I need to make a change to my Apache web server to redirect requests for the home page from iPhone browsers to a different page. I've edited the /etc/httpd/conf/httpd.conf file and added the following:
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*iPhone.*
RewriteRule ^/$ /iphone/index.html [L]
After making the change, I restarted httpd, but the redirect doesn't work.
Am I missing something? Do the edits need to be made to a specific location in the httpd.conf file?
Other info: Server is vps hosted by Lunarpages running CentOS 5.5 and Apache 2.2.3.
For me, I use like below
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*iPhone.*
RewriteRule ^[\./]$ <MyDomain>/iphone/index.html [L]
can someone tell me how to convert apache iis7 mod_rewrite .htaccess file to the equivalent web.config in MS Url Rewriter?
Here is the .htaccess file I have:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php?url=$1 [QSA,L]
</IfModule>
These look like WordPress rules. WordPress understands and knows how to modify the IIS 7 web.config file automatically. If you use the platform installer to install WordPress you don't have to worry about any of this:
http://www.microsoft.com/web/downloads/platform.aspx
There is also an Apache Rewriter config import into Microsoft URL Rewriter. And if you truly like Apache style syntax there is the URL Rewriter project provided by Managed Fusion, which supports Apache rules on IIS 6 and 7:
http://urlrewriter.codeplex.com