mod_rewrite issues

DK …i heard you were good at this stuff so who better to ask!

i have a issues with .htaccess mod-rewrite issues with two domain/url and the main/root directory

This is concerning a htaccess file and mod_rewrite.

i have two domains/urls,(just got the second domain/url today and am working on a webpage)

the first url being used for the root directory

the second i pointed to a folder inside the main/root directory which should load the webpage when i type in the url in the web browser.

however it only loads the webpage index.html file (when i rename the htaccess file from the original name htaccess to htaccess1) or when i type in the full path www.example.com/index.html.

the htaccess file is preventing the second url from loading the index.html file inside of the sub-directory. by just typing www.example.com. ( Note: the htaccess file was coded by another coder who created the first webpage, and he is no longer working with us )

i am trying to make the second url work as well with out having to type the full path www.example.com/index.html and with out messing up the code in the htaccess which works for the other domain name.

The current code looks like this.

<IfModule mod_rewrite.c> RewriteEngine on MultiViewsMatch Handlers Filters RewriteCond %{http_host} ^www.EXAMPLE.com [nc] RewriteRule ^(.*)$ http://EXAMPLE.com/$1 [r=301,nc] RewriteRule ^([^/\.]+)/?$ /category.php?cat=$1 [L] </IfModule>

if you can figure this out or let me know what to put in to make both domains work it would be great-Thanks

MM,

Welcome to SitePoint!

You should have started your own thread as that’s the way to get attention to your title/question.

When showing code, it helps to use the [noparse]

 ... 

[/noparse] wrapper.

Okay, web hosting usually works with a main domain and then “Addon Domains” added as subdomains of the main domain which are located in a subdirectory of the main domain like

domain1 - http://www.domain1.com with its own .htaccess and index.html

domain2 - http://www.domain2.com with its own .htaccess and index.html OR
http://www.domain1.com/domain2 OR
http://domain2.domain1.com

You can access domain1 and domain2 from domain1.com but you can only access domain2 from domain2.com (and the .htaccess in domain1 will not “hijack” domain2 requests).

Another point is that the .htaccess file can only be accessed by the server with that name. If you remove the leading dot, add .txt or any other changes, it won’t be recognized by Apache (unless the name of that file is altered by the host in the httpd.conf file, Apache’s configuration file).

To set the DirectoryIndex, use

DirectoryIndex index.htm index.html index.php

and the first file in the directory which Apache finds will be served (when the filename is not submitted with the request).

[COLOR="#FF0000"]<IfModule mod_rewrite.c>[/COLOR]
# Use this only once to test a redirection then NEVER use it again. It's so VERY abusive of the server that I created a standard rant:

[rant #4][indent]The definition of an idiot is someone who repeatedly does the same thing expecting a different result.  Asking Apache to confirm the existence of ANY module with an <IfModule> ... </IfModule> wrapper is the same thing in the webmaster world.  DON'T BE AN IDIOT!  If you don't know whether a module is enabled, run the test ONCE then REMOVE the wrapper as it is EXTREMELY wasteful of Apache's resources (and should NEVER be allowed on a shared server).[/indent][/rant 4]

RewriteEngine on

MultiViewsMatch Handlers Filters
# MultiViews is a dumb thing which I NEVER use as the consequences can be baffling when the requested file is "hijacked"

RewriteCond %{http_host} ^www[SIZE=5]\\[/SIZE].EXAMPLE[SIZE=5]\\[/SIZE].com [nc]
RewriteRule ^(.*)$ http://EXAMPLE.com/$1 [r=301[COLOR="#FF0000"],nc[/COLOR]]
# The No Case flag is designed for use with case insensitive variables (like {HTTP_HOST}), NOT with the {REQUEST_URI}!

RewriteRule ^([^/\\.]+)/?$ /category.php?cat=$1 [L]
[COLOR="#FF0000"]</IfModule>[/COLOR]

Okay, sorry for seeming to be somewhat abusive but this information is all in the tutorial article linked in my signature (and this information is for all members, not just for you). Okay, the setup of domains isn’t but many members have commented upon the mod_rewrite tutorial as extremely beneficial. Please have a read then come back with any questions you have.

Regards,

DK

Ok Thank you, i checked out your tutorials also. The issues is solved by me creating a new .htaccess in the sub directory. Thanks for your help

-MusicMetabolism

MM,

:Partier: Another fast learner helped by the tutorial! Welcome to the Wonderful World of mod_rewrite!

Regards,

DK