我在将 mod_rewrite 规则从 conf.d 文件夹中移出后在 .htaccess 中工作时遇到问题。 为了性能起见,我确实理解将它留在那里会更明智,但我在文档根目录上有一个为 php 服务的文件夹,我不希望应用这些相同的规则。
就在这里..我们将不胜感激任何帮助!
<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>
使用额外配置编辑:
<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>
最佳答案
如@Jason McCreary 所述,您可以将重写规则放在 <Directory>
中部分。它将仅限于该目录。 Directory
的主要优势与 .htaccess
是您不需要在 AllowOverride
中允许任何内容.那就是:
- 更安全:没有任何人使用 .htaccess (
use AllowOverride None
) 更改 apache 配置的风险 - 更快:apache 不需要在您的目录或所有父目录中搜索任何 .htaccess(我们在
AllowOverride None
部分中的<Directory />
,从文件系统顶部开始)
现在在 .htaccess
中使用重写引擎时有一些不同。例如,您可能需要使用 rewriteBase 播放文件。
关于php - 将 mod_rewrite 规则从 conf.d 移动到 .htaccess,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6673446/