Find the answer to your Linux question:
Results 1 to 2 of 2
Hi, I need help rewriting URLs in Apache. I want the 'www.' to be stripped while preserving the directory structure. For example: If a user types 'www.hex1a4.net/mirror/openoffice/' the URL should ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Linux Newbie x1a4's Avatar
    Join Date
    Dec 2006
    Posts
    123

    [SOLVED] Apache: Need help rewriting URLs


    Hi,

    I need help rewriting URLs in Apache. I want the 'www.' to be stripped while preserving the directory structure. For example: If a user types 'www.hex1a4.net/mirror/openoffice/' the URL should be rewritten as 'hex1a4.net/mirror/openoffice/' and the root of my OpenOffice mirror should be shown.

    I'm having a really hard time coming up with the correct rewrite conditions. So far I was able to come up with the following:
    Code:
    RewriteCond %{HTTP_HOST} ^www.hex1a4.net$
    RewriteRule ^(.*)$ http://hex1a4.net/ [R=301,L]
    but this doesn't doesn't take into account the directory structure and regardless of the path specified, if the address is prefixed with 'www.' the home page will always be displayed.

    Please note that I am not the admin of the system and don't have access to Apache's configuration files. I can only use .htaccess.The Apache version is 1.3.37
    Linux user 439038 | Ubuntu user 20892

  2. #2
    Linux Newbie x1a4's Avatar
    Join Date
    Dec 2006
    Posts
    123
    Well I've been reading up on rewriting URLs creating some easier ones, and it turns out this is just as easy. Here's how I did it:
    Code:
    RewriteCond %{HTTP_HOST} ^www\.hex1a4\.net(.*)$
    RewriteRule ^(.*)$ http://hex1a4.net/$1 [R=301,L]
    Linux user 439038 | Ubuntu user 20892

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •