I have apache with ngnix as a reverse proxy.
I have
RewriteRule ^thumb/(.*)x(.*)/r/(.*) thumb.php?w=$1&h=$2&src=$3
RewriteRule ^medias/(.*) files.php?file=$1
How to rewrite theme in nginx ?
Regards
The essential difference between Apache and nginx URIs, is that all nginx URIs begin with a leading /.
You should try:
rewrite ^/thumb/(.*)x(.*)/r/(.*) /thumb.php?w=$1&h=$2&src=$3? last;
rewrite ^/medias/(.*) /files.php?file=$1? last;
See this document for more.
Related
I am using Crafter CMS with multi-tenancy. I am trying to setup Apache2.4 on RHEL7 to be a reverse proxy. http://site.example.com -> ajp://localhost:9009/?crafterSite=site
Here is my Apache2 virtual host configuration. I have ensured that mod_proxy and mod_rewrite are loaded. I can reach Crafter Delivery through the proxy but the rewrite isnt working as Crafter doesnt know what site I am trying to load. Does anyone have any suggestions on how to get this working.
<VirtualHost *:80>
ServerName site.example.com
LogLevel alert rewrite:trace3
RewriteEngine On
RewriteRule ^$ /?crafterSite=site [QSA,L]
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyRequests Off
ProxyPreserveHost On
ProxyPass / ajp://localhost:9009/
ProxyPassReverse / ajp://localhost:9009/
</VirtualHost>
Try changing the rewrite rule to be:
RewriteRule (.*) $1?crafterSite=site [QSA,PT]
Where site is your site ID.
The differences are:
It rewrites anything coming in regardless of URL and preserves it (see the (.*) and $1)
It's a passthrough PT (not a redirect). This means it augments the request with the param and lets it straight through to Crafter Engine.
I have working apache connected with tomcat (mod_jk), I have set two virtualhosts:
myexample_8080.conf
myexample_4430.conf
I want to redirect all requests from http to https and on the home page of https://myexample.com redirect to tomcat url https://myexample.com/login
This is my first rule in myexample_8080.conf
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/?(.*) https://myexample.com/$1 [R,L]
Everytime I ended up with redirect loop.
Solution
RedirectMatch 301 ^/*$ https://myexample.com/info
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.
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 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]