I am having difficulty defining a correct RewriteRule to forward requests to an application running in tomcat.  I have apache with mod_rewrite enabled as well as tomcat setup with an application mounted with mod_jk.  Without a virtual host, I can browse to the following url without issue. (context being the application running in tomcat)  http://www.domain.com/context   How do I configure the RewriteRule to pass requests from domain.com to the application running in tomcat.  http://www.domain.com --&gt; http://www.domain.com/context   Here is what my current virtual host file looks like  &lt;VirtualHost *:80&gt;         ServerName www.domain.com          &lt;Directory /&gt;                 Options FollowSymLinks                 AllowOverride None                 RewriteEngine On                 RewriteRule \/$ /context [L]         &lt;/Directory&gt;          &lt;Directory /var/www/html/context/&gt;                 Options Indexes FollowSymLinks MultiViews                 AllowOverride None                 Order allow,deny                                                          allow from all                                                    &lt;/Directory&gt;  &lt;/VirtualHost&gt;   This will pass the request from domain.com to a directory named context in /var/www/html.  How do I override the default apache setup to pass the request to the application running in tomcat?  Thanks in advance for your help.
487
This is a  about Apache's mod_rewrite.   Changing a request URL or redirecting users to a different URL than the one they originally requested is done using mod_rewrite. This includes such things as:   Changing HTTP to HTTPS (or the other way around) Changing a request to a page which no longer exist to a new replacement. Modifying a URL format (such as ?id=3433 to /id/3433 ) Presenting a different page based on the browser, based on the referrer, based on anything possible under the moon and sun. Anything you want to mess around with URL   Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask!  How can I become an expert at writing mod_rewrite rules?   What is the fundamental format and structure of mod_rewrite rules? What form/flavor of regular expressions do I need to have a solid grasp of? What are the most common mistakes/pitfalls when writing rewrite rules? What is a good method for testing and verifying mod_rewrite rules? Are there SEO or performance implications of mod_rewrite rules I should be aware of? Are there common situations where mod_rewrite might seem like the right tool for the job but isn't? What are some common examples?   A place to test your rules  The  web site is a great place to play around with your rules and test them. It even shows the debug output so you can see what matched and what did not.
43829
I am using ASP.NET 2.0 C#. I want to redirect all request for my web app with "www" to without "www"  www.example.com to example.com  Or  example.com to www.example.com  Stackoverflow.com is already doing this, I know there is a premade mechanism in PHP (.htaccess) file. But how to do it in asp.net ?  Thanks
81858
If I ask Apache for domain.com that has no Virtual Host setup in Apache configuration, Apache will show the default Virtual Host. How can I prevent this from happening or simply drop the connection?
57765
Compare these two RedirectMatch's. The first doesn't work: RedirectMatch 302 ^/redirect\.php[?]page=(.+)$ http://somewhereelse.com/$1  Versus this, which will redirect to http://somewhereelse.com/?page=wherever: RedirectMatch 302 ^/redirect\.php([?]page=.+)?$ http://somewhereelse.com/$1  Does RedirectMatch only match the URI and not the query string? Apache's documentation is a bit vague in this area. What I'm trying to do is extract the page query parameter and redirect to another site using it. Is that possible with RedirectMatch or do I have to use RewriteCond + RewriteRule?
11115
I am wondering what primers/guides/tutorials/etc. are out there for learning to rewrite URLs using Apache/.htaccess? Where is a good place to start?  My primary interest is learning how to point certain directories to others, and how to use portions of a URL as parameters to a script (i.e. "/some/subdirs/like/this" => "script.php?a=some&amp;b=subdirs&amp;c=like&amp;d=this").
105322
I have few different vhost created and every one has its own folder in /var/www/ like this /var/www/example1/ /var/www/example2/  Now, when I type url with www www.example1.com it points to the /var/www/example1/index.html so that's working fine, but when I type without www example1.com it points to /var/www/ and I can see all the folders, I don't have index.html in /var/www/. I looked  and created .htaccess in /var/www/:     RewriteEngine On     RewriteBase /     RewriteCond % ^example1.com [NC]     RewriteRule ^(.*)$ http://www.example1.com/$1 [L,R=301]  but it's not working. This is how the all vhosts look like: &lt;VirtualHost *:80&gt;         ServerAdmin webmaster@localhost         ServerName *example1*         ServerAlias *.*example1*         DocumentRoot /var/www/example1         &lt;Directory /&gt;                 Options FollowSymLinks                 AllowOverride All         &lt;/Directory&gt;         &lt;Directory /var/www/example1/&gt;                 Options Indexes FollowSymLinks MultiViews                 AllowOverride All                 Order allow,deny                 allow from all         &lt;/Directory&gt;          ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/         &lt;Directory &quot;/usr/lib/cgi-bin&quot;&gt;                 AllowOverride None  I have cleared browser cache. Any idea how to fix this?
1051
im trying to run a cgi script (.cgi) with tomcat. I am getting the below error and cant find out whats wrong. I know i should really use apache and mod proxy but this really isnt my area of expertise so im taking the easy way out!  Thanks for any help.   java.io.IOException: Cannot run program "perl" (in directory "C:\Java\tomcat\webapps\my_app_name\WEB-INF\cgi"): CreateProcess error=2, The system cannot find the file specified     java.lang.ProcessBuilder.start(ProcessBuilder.java:459)     java.lang.Runtime.exec(Runtime.java:593)     java.lang.Runtime.exec(Runtime.java:431)     org.apache.catalina.servlets.CGIServlet$CGIRunner.run(CGIServlet.java:1705)     org.apache.catalina.servlets.CGIServlet.doGet(CGIServlet.java:597)     javax.servlet.http.HttpServlet.service(HttpServlet.java:627)     javax.servlet.http.HttpServlet.service(HttpServlet.java:729)     org.tuckey.web.filters.urlrewrite.UrlRewriteFilter.doFilter(UrlRewriteFilter.java:738)     org.apache.struts2.dispatcher.FilterDispatcher.doFilter(FilterDispatcher.java:416)
69138
The situation  Across the entire domain, we'd like the URLs to hide file extensions and remove trailing slashes, independent of the domain name itself (as in, works on any domain).  Sample of our directory structure  We're not using index.* files except for the homepage.   /  /index.php /account.php /account  /subscriptions.php  /login.php /login  /reset-password.php     The goal  Some examples of how these files might be requested, and how they should look in the browser:   / and index.php --> mydomain.com (literally just the bare domain name). /account.php or /account/ or /account --> mydomain.com/account /account/subscriptions.php or /account/subscriptions/ or /account/subscriptions --> mydomain.com/account/subscriptions   As you can see, there are several ways to access each webpage, but no matter which of the 2 or 3 ways you use to get there, it only shows the one preferred URL in the browser.  The question  How is this done with .htaccess using mod_rewrite?  I've banged my head against the wall trying to figure this out, but in general, the rewrite flow would seem to be something like this:   External 301 redirect ( mydomain.com/account/ --> mydomain.com/account ) Internally append .php ( mydomain.com/account --> mydomain.com/account.php )   I've been Googling this all day, read thousands of lines of documentation and config texts, and have tried several dozen times... I think more brains on this would help a lot.  UPDATE  We found an answer our question (see below).
590
I would like to redirect www.example.com to example.com. The following htaccess code makes this happen:  RewriteCond %{HTTP_HOST} ^www\.example\.com [NC] RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]   But, is there a way to do this in a generic fashion without hardcoding the domain name?
84890
I have changed the configuration of Apache to point towards a folder in my home directory:  &lt;VirtualHost *:80&gt;     ServerAdmin webmaster@localhost      DocumentRoot /home/dbugger/html      &lt;Directory /&gt;         Options FollowSymLinks         AllowOverride None     &lt;/Directory&gt;     &lt;Directory /home/dbugger/html/&gt;         Options Indexes FollowSymLinks MultiViews         AllowOverride None         Order allow,deny         allow from all     &lt;/Directory&gt;      ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/     &lt;Directory "/usr/lib/cgi-bin"&gt;         AllowOverride None         Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch         Order allow,deny         Allow from all     &lt;/Directory&gt;      ErrorLog ${APACHE_LOG_DIR}/error.log      # Possible values include: debug, info, notice, warn, error, crit,     # alert, emerg.     LogLevel warn      CustomLog ${APACHE_LOG_DIR}/access.log combined      Alias /doc/ "/usr/share/doc/"     &lt;Directory "/usr/share/doc/"&gt;         Options Indexes MultiViews FollowSymLinks         AllowOverride None         Order deny,allow         Deny from all         Allow from 127.0.0.0/255.0.0.0 ::1/128     &lt;/Directory&gt;  &lt;/VirtualHost&gt;   I have even given my /home/dbugger/html permission 777. But I still keep getting the same error message at http://localhost: "403 Forbidden"  What is it that I am missing?
35370
I have a PHP application (Wordpress) in the root folder of my site, and all requests to the site run through it happily.   However, I have a subfolder, _links, which I would like to use to execute another, different php script.  Eg, if a user goes to site.com/_links/221312, then the index.php script from /_links takes over.  I formerly used a .htaccess file to achieve this, but since moving to nginx I can't make it work.   Here is the old .htaccess file.  RewriteEngine On RewriteRule    ^([0-9]+)/?$    index.php?linkid=$1    [NC,L]   Obviously, I'm passing the last bit of the URL to the script as a parameter.  Here is my nginx config. Requests to eg site.com/_links/23423 are picked up by if (!-e $request_filename) and rewritten to /index.php?q=/_links/23423 instead of being picked up by the location block.   server {         listen  127.0.0.1:8080;         server_name site.com www.site.com m.site.com;          root /var/www/site;         location ^~ /_links/ {                 add_header location 1;                 root /var/www/site/_links;                 rewrite "^([0-9]+)/?$" /index.php?linkid=$1 break;                 location ~ \.php$ {                         try_files $uri =404;                         fastcgi_pass unix:/var/run/php5-fpm.sock;                         fastcgi_index index.php;                         fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;                         include fastcgi_params;                  }          }         index index.php index.html;         if (!-e $request_filename)             {                 rewrite ^(.+)$ /index.php?q=$1 last;             }         location / {                 try_files $uri $uri/ =404;         }          # pass the PHP scripts to FastCGI server listening on the php-fpm socket         location ~ \.php$ {                 try_files $uri =404;                 fastcgi_pass unix:/var/run/php5-fpm.sock;                 fastcgi_index index.php;                 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;                 include fastcgi_params;          }         access_log /var/log/nginx/site.com.access.log;         error_log /var/log/nginx/site.com.error.log notice; }   I'm really confused. What's going on here?
70118
My apologies if this has been asked before. I haven't found an adequate solution so... yeah.  When a specific domain, "example.com" is accessed, I want it to act normally. In other words, it should go to port 80 as expected and interact with Apache.  When a different sub-domain, "mc.example.com" is accessed, I don't want it to access the Apache web server. I want it to go interact with a different program, listening on, say, port 4096. Thus, going to "mc.example.com" would have the same/similar function as "example.com:4096". The service is Minecraft  When a third sub-domain, "vpn.example.com" is accessed, I want it to go interact with a different service, listening on, say, port 687. The service is openVPN  Is there a simple way to do this? If so, what is it? Does it involve configuring a VirtualBox in Apache (a method I tried and failed miserably. xD)? Or can it be done using ipTables? If it means anything, I am running 32-bit Centos 5.5(I believe. Its a recent version of Centos)
56537
I have a number of staging and test servers that I need to constantly modify my hosts file to access (they depend on the domain name, so I have to change the hosts file to get them to work).  I find this annoying. I'd like to setup a portable browser of some kind for each kind of site I want to work with. Is there any version of any graphical web browser (including browsers based on the rendering engines of other browsers) that will do this?  This way I can simply launch the instance that's already configured to work with staging if I want to test staging.    Any ideas?  EDIT: The important feature is the ability to run two browsers concurently, both browsing to some-address.com, but with one browser directing the reqests to the server at 1.2.3.4 and the other browser directing the requests to the server at 5.6.7.8.  EDIT: (3/16/14)  This question was asked several years ago, and I still don't know of a decent way to do this.  Let me try to explain further, because people seem to misunderstand the problem.  It's not something that can be easily fixed just by using a proxy server.  I suppose it might be possible to write extensive rules in a proxy server to solve the problems, but that's a huge complex solution to what should be a simple problem.  So to clarify:  There are three web servers.  Production, Test, and Development.  Each runs a multi-tenant application that customizes itself based on the hostname used to access it.  Conceptually, this is similar to a Content Management System or blog engine that allows multiple sites to be run off the same server instance.  You just point the hostname to the server, and whichever hostname is used to access it via HTTP 1.1 hostname mapping, is the site it displays.  Any solution which simply rewrites the host file doesn't work because of the requirement to run multiple browser windows at the same time to the different sites, production, development, test, etc...  So simply constantly altering the host file doesn't work because it affects all browser instances.  If you change the mapping for one browser, then the other browsers are also now mapped to that server so any subsequent requests will go to the wrong server.  All i'm looking for is a way to force this browser instance to use this host file, and that browser instance to use that host file, such as through a command line parameter.  I don't even care if I need to install multiple copies of the browser.    This may be doable with firefox portable, since I think it uses its own config files per installed copy, but the problem is that the third party software used to administer the sites does not work with firefox (the sites themselves do, but the admin tools do not, they work fine with chrome and IE and Opera, however.. and I have no access to the source for this to fix it).
53840
I have the following in my httpd.conf file  NameVirtualHost *:80  &lt;IfModule mod_vhost_alias.c&gt;   &lt;VirtualHost *:80&gt;     ServerAlias *     UseCanonicalName Off     LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon     CustomLog /var/log/httpd/access_log vcommon     VirtualDocumentRoot /web-data/vhosts/%0/httpdocs     VirtualScriptAlias  /web-data/vhosts/%0/httpdocs   &lt;/VirtualHost&gt; &lt;/IfModule&gt;   This works great for dynamic hosting. However, I can't figure out how to make https requests work the same way. What do I need to add to this so that https and http for the same domain request get sent to the same folder?
13517
How can i use Tomcat to serve image files from a public folder outside webapps? I dont want to use a 2nd Apache fileserver on a different port since the image files are part of the same app. And i dont want to create a symlink to the public folder inside webapps since my app is deployed as a war file....Is there a simpler solution similar to using default servlet for static content inside webapps, for static content outside outside webapps
56911
I've been working with Apache http servers for quite some time, and finally making the move to static-content servers alongside the others dynamic-content machines.   I was wondering, does nginx support ".htaccess" files, and things like mod_rewrite?   As I'm very used to the syntax, I was wondering what the (syntax) differences were, and what the learning curve is like moving from Apache configs to nginx.
59229
I am need for apache to have access on all (well... most anyway) user folders on the same machine, so that I can access some data, do some magic and then display them on a webpage for remote viewing.  What I thought would be the simplest solution is to create a dir alias that points to /home folder and allowing it to be accessed only locally, since all the "magic" will be happening server side and only the results will be shown. Problem is I cannot make the Alias to work.  I added the following in my /etc/apache2/mods-enabled/alias.conf to check if it is working:  Alias /home/ "/home" &lt;Directory "/home"&gt;      Options Indexes MultiViews FollowSymLinks      AllowOverride None      Require all granted &lt;/Directory&gt;   but I'm getting a 403 Forbidden. I also tried adding it as a virtual host on sites-enabled/000-default.conf and apache2.conf neither of which worked.  I also added www-data to a user group that has access to /home, just to be sure.  What am I missing here?