apache2 - RewriteRule just change the name - apache

I have a folder with content in it. URL to it: http://www.example.com/something/
Is it possible now to rewrite the URL to this: http://www.example.com/learning/?
If yes, how?
Note: Folder something has some subfolders and a lot of HTML and PHP Files, including CSS and JS stuff.
Second note:: I can just edit my httpd.conf
Edit:
I'm using apache2 and jboss. apache2 just for the proxy and rewrite module. So my jboss application can be reached at this location: http://www.example.com:1231/something/.
I just defined that the jboss application ca be reached under port 80 at this url http://www.example.com/something/.
Now i wanna do the redirect like above.

This should work:
RewriteEngine On
RewriteRule ^/something(.*) http://www.example.com:1234/learning$1 [P]

Related

http://localhost:80 class not registered

I installed Bitnami wamp stack, and, though my installation is reachable by http:// [nameofmylaptop]/site , i have the following error each time I launch apache :
http://localhost:80
Class not registered
I can't find anything relating to this..
Any help ? Thank you.
Have you tried: localhost/site, it could be that since your website is in a subfolder called site, localhost root directory has nothing to display.
#Husman Yeah it works.
Theres your problem then, there is nothing in the root folder, you can have an apache redirect to take you from localhost to localhost/site, and that should fix your issue.
There are multiple ways to redirect:
use a server side script (index.php)
use .htaccess rewrite rule
RewriteEngine On
RewriteRule ^$ /site[L]
use apache config httpd.conf to redirect from one folder to another
Redirect permanent / http://git.example.com/git/
...

mod rewrite clear home url for tomcat + apache

I have a struts app running on Apache front end of Tomcat via mod-jk.
I am trying to use mod-rewrite to clean some of the action urls generate by struts.
Example: rewrite (works fine)
http://www.demo.com/context/user.do?action=aboutus to http://www.demo.com/context/aboutus using
RewriteRule ^/msn/aboutus$ /msn/user.do?action=aboutus [PT,L].
Problem: I'd like to rewrite the http://www.demo.com/context/user.do?action=home to http://www.demo.com (homepage)
I tried this
RewriteRule ^/$ /context/userdo?action=home [PT,L] which does not work.
FYI
All the css,js and links are on relative path.
DirectoryIndex is on index.html (Does it change mod-rewrite behaviour?)
Tomcat Version 5.5, Application deploy via exploding the WAR file in public_html/context/ folder (multiple deployment)
URLrewrite filter does not help to remove the context name according to this.
Logs
I tired to have a look at the log file (snapshots) which doesn't give any warning error messages.
(3) applying pattern '^/$' to uri '/context/jsps/images/abc.png'
(3) applying pattern '^/abc/aboutus$' to uri '/abc/jsps/images/abc.png'
(3) applying pattern '^/abc/home$' to uri
'/abc/jsps/images/abc.png'
Anyone can give me some ideas what went wrong? and how can I solve that issue?
I think in your case of rewriting ^/$ it is mod_jk that is taking precedence over mod_rewrite rules since using mod_jk you are forwarding everything eg: /* to Tomcat from Apache. I will suggest using URLRewriteFilter within your Tomcat app to achieve these URL rewrites properly.

url rewriting on localhost

I have WAMP installed on my local machine. I have configured the apache module for rewrite_mod and trying a very basic example to redirect
RewriteEngine on
RewriteRule ^alice.html$ bob.html
As per this rule when I hit alice.html I should be viewing bob.html content. But, I think the url rewriting is not effective.
I have /test folder placed under www and alice.html and bob.html both are place inside the test folder.
Any advice to resolve this.
Thanks
This is resolved.
Did you enable the mod_rewrite module for Apache ? You need to enable this module for using rewrite directives. Don't forget to restart Apache after enabling the module.

Apache rewrite rule with proxy flag fail to work for mediawiki service

I have a local apache httpd hosting a mediawiki service that listen to port 3300. The service may access in my LAN via
http://mylan:3300/wiki/
I configure my internet router to add a port forwarding entry to the mylan:3300. I may then access to the wiki via something like:
http://<dynamic domain>:3300/wiki/
Next, I have a web site that serve globally. The web server is apache httpd too. I add a rewrite rule in .htaccess:
RewriteEngine On
RewriteRule ^/?wiki/?$ http://<dynamic domain>:3300/wiki/ [P]
I wish to access the wiki that host on my local LAN via the proxy method but using the global internet domain namespace:
http://<internet domain>/wiki/
After execute the above URL from internet browser, I can see the wiki contents. However, the URL shown in address bar change to
http://<dynamic domain>:3300/wiki/index.php/Main_Page
In order to test the proxy rewrite rule work, I try to change the rewrite rule to:
RewriteRule ^/?wiki/?$ http://www.google.com/search?q=test [P]
Open the URL:
http:///wiki/
lead me to google search page but the URL remain as http:///wiki/.
Any ideas why the rewrite rule
RewriteRule ^/?wiki/?$ http://<dynamic domain>:3300/wiki/ [P]
make the browser show the new URL address instead of internet domain name space:
http://<internet domain>/wiki/
A good example is:
RewriteRule ^/?wiki/(.*)$ http://en.wikipedia.org/wiki/$1 [P]
If we access the url:
http://<domain>/wiki/Country
The URL will always rewrite and shown as
http://en.wikipedia.org/wiki/Country
Instead, I expect it to show as
http://<domain>/wiki/Country
but the content is from http://en.wikipedia.org/wiki/Country
Probably a redirect that includes the full link. To rewrite them add something like:
ProxyPassReverse /wiki/ http://<dynamic domain>:3300/wiki/
I also notice in the Apache online documentation for URL Rewriting Guide - Advanced topics in the section on Content Handling, sub section Dynamic Mirror has this example:
RewriteEngine on
RewriteBase /~quux/
RewriteRule ^hotsheet/(.*)$ http://www.tstimpreso.com/hotsheet/$1 [P]

How to configure apache (ubuntu) such that www.mysite.com will direct to www.mysite.com/drupal6/?

I am a newbie to ubuntu and apache. Can someone tell me how I could direct to
www.mysite.com/drupal6
when user address www.mysite.com?
Thanks a lot.
Cheers.
If you are running Apache and Ubuntu, there is actually a really easy way to force this redirect using a simple php script.
Create an index.php file in the root of your server and paste the following code into it
<?php header("location: drupal6/") ?>
This will cause the site to auto-redirect to the drupal6 folder whenever it is visited.
This should work. Create a file in the root folder of your server called .htaccess - the dot at the beginning is very important as this helps the server identify the file as a hidden / system config file.
Open the file and paste the following lines of code in :
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ www.mysite.com/drupal6/$1 [R,L]
This should force all traffic to the server to redirect to your custom folder.
A brief explanation of the .htaccess code
If you want rewrites to work, you have to enable the Rewrite Engine and tell the server to follow symlinks.
The second section establishes the rule - specifically applying it to all traffic on the standard web port of 80.
The final line tells the server to grab everything after the URL and append it to the new address (mysite.com/drupal6).
There's a lot more you can do with .htaccess files but you really need to Google for good examples to test out.
Look at Apache's mod_rewrite documentation. You will need a RewriteRule in your apache configuration at the minimum, you may also need RewriteCond's to define when the RewriteRule is used.
Your rewrite pattern will be rewriting the REQUEST_URI with something from: ^/$ to: /drupal6. The ^ and $ are essential to prevent Apache getting into an infinite loop while rewriting the base URI by only matching "/" and not "/anything-else".
I assume you're on a recent version of Ubuntu and Apache? If so, see the Apache 2.2 documentation on mod_rewrite.