Changing the context root of an application - mod-rewrite

I have two servers (dev1 and dev2) an application with context root app is hosted on both these servers i can access these application by thier url e.g.
http://dev1:8080/app
http://dev2:8080/app
so want is
http://dev1/app1 redirect to dev1 app
http://dev1/app2 redirect to dev2 app
i have apache 2.2 installed on dev1 server and tried the following
httpd.conf
<IfModule rewrite_module>
RewriteEngine On
JkOptions +ForwardURICompat
RewriteCond %{REQUEST_URI} ^(.*)app1(.*)$
RewriteRule ^(.*)app1(.*)$ $1app$2 [PT,L]
RewriteCond %{REQUEST_URI} ^(.*)app2(.*)$
RewriteRule ^(.*)app2(.*)$ $1app$2 [PT,L]
</IfModule>
worker.properties
worker.list=node1,node2
worker.node1.type=ajp13
worker.node1.host=dev1
worker.node1.port=8009
worker.node2.type=ajp13
worker.node2.host=dev2
worker.node2.port=8009
mod_jk.conf
JkMount /app1/ node1
JkMount /app1/* node1
JkMount /app2/ node2
JkMount /app2/* node2
EDIT:
redirect is working now but all the application url are now redirecting to
http://dev1/app instead of (http://dev1/app1 or http://dev1/app2)

Related

Route is not working in my CI live server

This is mine route directory .htaccess file
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]
the app is working only for home route i changed it from
$route['default_controller'] = 'home';
$route['default_controller'] = 'login';
but it is not working
You need to make sure rewrite_module is enabled on your server
sudo a2enmod rewrite
Then restart your apache
sudo systemctl restart apache2
Then add this to your config file under sites-available
<VirtualHost *:80>
<Directory /var/www/SITE_DIRECTORY>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
. . .
</VirtualHost>
Finally add RewriteEngine on to your .htaccess

How to get mod rewrite condition "if variable is not" to work

I've installed Oracle Apex and trying to deploy multiple applications with a apache reverse proxy but I cannot get apache to limit a virtual host to one application id.
The virtual host
<VirtualHost *:80>
ServerName www.example.com
ServerAlias test.example.com
ServerAlias example.com
ProxyPass / http://127.0.0.1:8080/ords/
ProxyPassReverse / http://127.0.0.1:8080/ords/
RewriteCond %{QUERY_STRING} !^p=101$
RewriteRule ^/$ f?p=101 [L,P]
<Location /i>
ProxyPass http://127.0.0.1:8080/i
ProxyPassReverse http://127.0.0.1:8080/i
</Location>
</VirtualHost>
What im trying to do is if the variable p is not 101 I want the proxy to redirect the user /f?p=101 so only the application that I want on that virtual host is accessible and not the other application but I wont work.
If I do /f?p=102 it will show the other application and not redirect me to application 101 again.
Does anyone know how to fix this?
I found the solution:
RewriteCond %{QUERY_STRING} ^f?p=100 [OR]
RewriteCond %{QUERY_STRING} ^f?p=4550 [OR]
RewriteCond %{QUERY_STRING} ^f?p=4000
RewriteRule ^/(.*) https://%{HTTP_HOST}/f?p=101:1 [R]
So what I am doing is checking if we get the application ID I need to filter out.
After that I just redirect the page to the original page for the application.

mod_rewrite redirects to .html in error

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.

How to change htaccess to access symfony web directory

I am running symfony2 in Windows7 and Xampp:
http://localhost/symfony/web/app_dev.php/hello/symfony
How do I change web/.htaccess file to access symfony using the link below?
http://localhost/app_dev.php/hello/symfony
the default .htaccess is:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
I tried adding Rewrite RewriteBase /symfony/web/ or RewriteBase symfony/web/ then php app/console cache:clear --env=prod --no-debug and also tried restarting apache.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ app.php [QSA,L]
RewriteBase /symfony/web/ OR RewriteBase symfony/web/
And can I do the same in Nginx with Reverse proxy? How to change to access without symfony/web?
tried add 127.0.0.1 www.mysymfony.com.localhost
into etc/hosts
add the following into httpd.conf
# Be sure to only have this line once in your configuration<br>
NameVirtualHost 127.0.0.1:80
# This is the configuration for your project
Listen 127.0.0.1:80
<VirtualHost 127.0.0.1:80>
ServerName www.mysymfony.com.localhost
DocumentRoot "D:\xampp\htdocs\symfony\web"
DirectoryIndex app.php
<Directory "D:\xampp\htdocs\symfony\web">
AllowOverride All
Allow from All
</Directory>
</VirtualHost>
access this link
http://www.mysymfony.com.localhost/app_dev.php/demo/hello/symfony
it gives an error,doesnt have this link

Apache mod-rewrite in httpd.conf not working

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]

Resources