Forum Moderators: phranque

Message Too Old, No Replies

disable mod_rewrite for specific directories

         

keithmcd

5:15 am on Mar 19, 2005 (gmt 0)

10+ Year Member



The following is the section of my .htaccess that deals with the mod_rewrite:
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

Now here's the problem. I have clean links enabled on my site's software (drupal) and I want to keep it on. It makes the site great for search engines and much easier for users to understand. However, I have some directories on my site that are not a part of drupal, but are still on the main site. I want to allow those directories to go through normally while letting druapl keep it's rewrite rules.

I have no clue about rewrite rules as druapl automatically created the .htaccess file for me.

Any help is greatly appreciated!
Keith McDermott

[edited by: jdMorgan at 10:08 pm (utc) on Mar. 22, 2005]
[edit reason] No sigs, please. [/edit]

jdMorgan

10:14 pm on Mar 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Keith,

Welcome to WebmasterWorld!

There are several ways to do this.

The most foolproof way to do it would be to bypass the drupal mod_rewrite directives for those directories. For example to bypass the rules for the subdirectory "/no_rewrite/mystuff/dir1/" you would add the code:


RewriteRule ^no_rewrite/mystuff/dir1 - [L]

ahead of the RewriteRules for drupal.

This says, "If the requested local URL-path starts with 'no_rewrite/mystuff/dir1/', then don't change the URL, and stop rewriting."

Jim

keithmcd

11:21 pm on Mar 22, 2005 (gmt 0)

10+ Year Member



Sweet! Many many thanks. I have been looking for an answer to this very question through google for some time with no success.

OK - I added the lines but it still redirects me to the main page. Maybe there's something else in my htaccess? Below is the whole thing. Let me know if you see something or if the code you told me to add is wrong - it is relative to the web root and not the server root right?

.htaccess file contents:
---------------------------------------------
#
# Apache/PHP/site settings:
#

# Protect files and directories from prying eyes:
<Files ~ "(\.(conf¦inc¦module¦pl¦sh¦sql¦theme¦engine¦xtmpl)¦Entries¦Repositories¦Root¦scripts¦updates)$">
order deny,allow
deny from all
</Files>

# Set some options
Options -Indexes
Options +FollowSymLinks

# Customized server error messages:
ErrorDocument 404 /index.php

# Set the default handler to index.php:
DirectoryIndex index.php

# Overload PHP variables:
<IfModule mod_php4.c>
# If you are using Apache 2, you have to use <IfModule sapi_apache2.c>
# instead of <IfModule mod_php4.c>.
php_value register_globals 0
php_value track_vars 1
php_value short_open_tag 1
php_value magic_quotes_gpc 0
php_value magic_quotes_runtime 0
php_value magic_quotes_sybase 0
php_value arg_separator.output "&amp;"
php_value session.cache_expire 200000
php_value session.gc_maxlifetime 200000
php_value session.cookie_lifetime 2000000
php_value session.auto_start 0
php_value session.save_handler user
php_value session.cache_limiter none
php_value allow_call_time_pass_reference On
</IfModule>

# Various rewrite rules
<IfModule mod_rewrite.c>
RewriteEngine on

# Modify the RewriteBase if you are using Drupal in a subdirectory and the
# rewrite rules are not working properly:
#RewriteBase /drupal

# Rewrite old-style URLS of the form 'node.php?id=x':
#RewriteCond %{REQUEST_FILENAME}!-f
#RewriteCond %{REQUEST_FILENAME}!-d
#RewriteCond %{QUERY_STRING} ^id=([^&]+)$
#RewriteRule node.php index.php?q=node/view/%1 [L]

# Rewrite old-style URLs of the form 'module.php?mod=x':
#RewriteCond %{REQUEST_FILENAME}!-f
#RewriteCond %{REQUEST_FILENAME}!-d
#RewriteCond %{QUERY_STRING} ^mod=([^&]+)$
#RewriteRule module.php index.php?q=%1 [L]

# Disable rewrite for specific directories
RewriteRule ^Keith - [L]
RewriteRule ^PNC - [L]
RewriteRule ^SOL - [L]
RewriteRule ^jake - [L]
RewriteRule ^errors - [L]
RewriteRule ^webalizer - [L]
RewriteRule ^modlogan - [L]
RewriteRule ^people - [L]
RewriteRule ^software - [L]
RewriteRule ^swg - [L]
RewriteRule ^teri - [L]
RewriteRule ^test - [L]

# Rewrite URLs of the form 'index.php?q=x':
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>

# $Id: .htaccess,v 1.58 2004/10/09 20:41:49 dries Exp $

jdMorgan

12:35 am on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



add the code:

RewriteRule ^no_rewrite/mystuff/dir1 - [L]

ahead of the RewriteRules for drupal.

All in the details... ;)

Jim

keithmcd

5:59 am on Mar 23, 2005 (gmt 0)

10+ Year Member



Uh... the only rewrite stuff that was in front of the custom stuff based off what you had said was all commented out already.

Anyway, I tried moving around the new stuff to various parts of .htaccess, but it still keeps redirecting me to the main page. The various changes I tried were to move my custom stuff to the very beginning of htaccess, then to the beginning of the mod_rewrite section and so on. In all changes it keeps reverting back to the root. The only thing I can think of is that the server cache's the .htaccess for a time? If not, then I'm still stuck.

jdMorgan

7:14 am on Mar 23, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Sorry, I didn't read the lines, just scanned the headers.

Try going into one or more of your subdirectories, such as "/jake", and adding RewriteOptions inherit to .htaccess in that subdirectory. Then test those subdirectories. This will force Apache to process your Web-root-level .htaccess before processing the subdirectory.

Whenever you work on any server-side code that modifies the content returned by a given URL, or that modifies access controls, you'll need to flush your browser cache, and any other intervening caches (such as your local caching proxy if you run one). Otherwise, your browser will return its local copy of the content you requested, and the request will never be sent to your server. (I'm assuming here that you have not marked the content as non-cacheable on the server).

Jim

keithmcd

2:30 pm on Mar 23, 2005 (gmt 0)

10+ Year Member



Well, I had never had a .htaccess in any directory except the root of my site but i made one and put it in /PNC. I am still getting redirected to the main page. I copied the mod_rewrite section off the root htaccess and put it in the /PNC one, removed all the lines in the rewrite section except for engine on, added your line but it still wouldn't work. I think I'm ready to just give up and just add some server side redirects to some sub domains. I don't have shell access to the server so I can't do anything too drastic myself - I have to use a tool called "HSphere" to do most of the server side stuff.

Anyway, thanks for your help with all this and if you have any other ideas I'd be happy to try anything so long as it doesn't break the main site! :-)

antonello

12:51 pm on Mar 26, 2005 (gmt 0)

10+ Year Member



Try this:

# Rewrite URLs of the form 'index.php?q=x':
RewriteCond %{REQUEST_FILENAME}!-f
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{THE_REQUEST}!/subd1
RewriteCond %{THE_REQUEST}!/subd2
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

and make another htaccess in the directories with a DirectoryIndex