Plastika
Plastika

Reputation: 223

Moving mod_rewrite rules from conf.d to .htaccess

I am having an issue with getting mod_rewrite rules working in .htaccess after moving them from the conf.d folder. I do understand for performance sake that it would be wiser to leave it sitting there but I have folder serving php on the document root which I do not want these same rules applied to.

And here it is.. Any and all help would be greatly appreciated!

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^/([^/]*)/(\d+)/? /index.php?p=$1&id=$2 [QSA,L]
    RewriteRule ^/([^/]*)/([^/]*)/(\d+)/? /index.php?p=$1&s=$2&id=$3 [QSA,L]
    RewriteCond %{REQUEST_URI} !/(manual|admin|awstats)
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-d
    RewriteRule ^/([^/]*)/?([^/]*)/? /index.php?p=$1&s=$2 [QSA,L]
</IfModule>

Edited with additional config:

<Location "/admin/">
    SetHandler python-program
    PythonHandler django.core.handlers.modpython
    SetEnv DJANGO_SETTINGS_MODULE site.settings
    #PythonDebug Off
</Location>

Alias /adminmedia/ "/usr/lib/python2.4/site-packages/django/contrib/admin/media/"

<Directory "/usr/lib/python2.4/site-packages/django/contrib/admin/media">
    Options -Indexes MultiViews
    AllowOverride None
    Order allow,deny
    Allow from all
</Directory>

Upvotes: 3

Views: 679

Answers (2)

regilero
regilero

Reputation: 30526

as astated by @Jason McCreary you can put your rewriteRules in a <Directory> section. It will be limited to that directory only. The main advantage from a Directory versus a .htaccess is that you do not need to allow anything in AllowOverride. So that's:

  • safer: no risk of anyone altering apache configuration by using a .htaccess (use AllowOverride None)
  • faster: apache does not need to search for any .htaccess in your directory or in all the parents directories (us your AllowOverride None in a <Directory /> section, start on top of the filesystem)

Now there are some difference on the rewrite Engine when used in .htaccess files, you may need to play with rewriteBase for example.

Upvotes: 2

Dr.Molle
Dr.Molle

Reputation: 117354

Be sure that the directory is configured with AllowOverride FileInfo (this is required for using the RewriteEngine)

Upvotes: 1

Related Questions