url rewriting on localhost - apache

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.

Related

apache2 - RewriteRule just change the name

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]

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/
...

htaccess issue with seo friendly urls - GoDaddy

OK, I'm looking to use mod rewrite to write seo friendly urls for my site. It works fine on my xampp local testing server. However, I'm having problems when trying to put it live, it doesn't seem to work at all.
Here's what I've written in my htaccess file:
RewriteEngine On
RewriteRule ^category/([a-zA-Z0-9]+)$ category.php?location=$1
So the idea is to change mysite.com/category.php?location=londonto mysite.com/category/london.
Initially I though it may be an issue with the ability to mod rewrite being switched on on GoDaddy's end, so I contacted GoDaddy to see if it that was the case and their response was that: "Mod_rewrite is an Apache Web server module installed on all of our Linux servers by default; it does not have to be installed or enabled. Our Linux hosting accounts support most mod_rewrite functions. Because enabling mod_rewrite is handled at a global level, you do not need to enable it in your httpd.conf file. You only need to add the desired code to the body of your .htaccess file."
And they bascially implied that the error is not with them and with my code. I'm not very experienced with mod rewrites and it seemed to work fine when I wrote it like this on other servers. Is there something special you have to write with godaddy? Am I missing something? Thanks!
Is that all in your htaccess file? What error do you get when visiting a desired URL, is it a 500 Internal Server error?
What I usualy add by default is an If-statement:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteRule ^category/([a-zA-Z0-9_-]+)$ category.php?location=$1 [L]
</IfModule>
By the way, note the _- at the end of the charset in the rule, for instance New York has a SEF version which is new-york, category/new-york would fail in your RewriteRule.

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.

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.