开发者

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_SETTING开发者_如何学CS_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>


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜