我有一组 html 文件位于:www.example.com 和“主站点”(测试版)位于:www.example.com/abcd/(需要这些 mod_rewrite 规则)
mod_rewrite 规则在 .htaccess 中的目录中运行良好。我需要把它们放在 httpd.conf 中:
.htaccess 中的规则如下所示:
RewriteEngine On
RewriteBase /abcd/
RewriteRule ^.*/codelibrary/(.*)$ codelibrary/$1 [L]
RewriteRule ^.*/in_upload/images/(.*)$ in_upload/images/$1 [L]
...
将以下内容复制到 httpd.conf 文件中不起作用:
<VirtualHost *:80>
ServerAlias www.example.com
ServerAdmin nobody@example.com
DocumentRoot /var/www/html
ServerSignature On
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /abcd/
...
它给出了一个错误:
RewriteBase: only valid in per-directory config files
我需要像这样修改所有规则吗?
RewriteRule ^.*/abcd/codelibrary/(.*)$ abcd/codelibrary/$1 [L]
RewriteRule ^.*/abcd/in_upload/images/(.*)$ abcd/in_upload/images/$1 [L]
编辑1
我试图转换以下行:
...
RewriteRule (.*)ins.html$ browse.php?type=ins [L]
...
RewriteRule ^([a-zA-Z\-]*)/([a-zA-Z0-9\s]*)/([0-9]*)\.html$ browse.php?type=$1&catId=$3 [L]
RewriteRule ^([a-zA-Z\-]*)/([a-zA-Z0-9\s]*)/([a-zA-Z0-9\s]*)/([0-9]*)/([0-9]*)\.html$ browse.php?type=$1&catId=$4&subCatId=$5 [L]
...
到:
...
RewriteRule ^/abcd/ins.html$ abcd/browse.php?type=ins [L]
...
RewriteRule ^/abcd/([a-zA-Z\-]*)/([a-zA-Z0-9\-\s]*)/([0-9]*)\.html$ abcd/browse.php?type=$1&catId=$3 [L]
RewriteRule ^/abcd/([a-zA-Z\-]*)/([a-zA-Z0-9\-\s]*)/([a-zA-Z0-9\-\s]*)/([0-9]*)/([0-9]*)\.html$ abcd/browse.php?type=$1&catId=$4&subCatId=$5 [L]
...
但我得到如下错误。
当我尝试访问http://www.example.com/abcd/ins/Sustainability/282.html时,我在日志中收到以下错误:
IPADDRESS - - [DATETIME] [www.example.com/sid#2b3cde3c1be0][rid#2b3cec076e70/initial] (2) init rewrite engine with requested uri /abcd/ins/Sustainability/282.html
IPADDRESS - - [DATETIME] [www.example.com/sid#2b3cde3c1be0][rid#2b3cec076e70/initial] (2) rewrite '/abcd/ins/Sustainability/282.html' -> 'abcd/browse.php?type=ins&catId=282'
IPADDRESS - - [DATETIME] [www.example.com/sid#2b3cde3c1be0][rid#2b3cec076e70/initial] (2) local path result: abcd/browse.php
当我尝试访问http://www.example.com/abcd/ins.html时,我在日志中收到以下错误:
IPADDRESS - - [DATETIME] [www.example.com/sid#2b3cde3c1be0][rid#2b3cec076e70/initial] (2) init rewrite engine with requested uri /abcd/ins.html
IPADDRESS - - [DATETIME] [www.example.com/sid#2b3cde3c1be0][rid#2b3cec076e70/initial] (2) rewrite '/abcd/ins.html' -> 'abcd/browse.php?type=ins'
IPADDRESS - - [DATETIME] [www.example.com/sid#2b3cde3c1be0][rid#2b3cec076e70/initial] (2) local path result: abcd/browse.php
我已将 RewriteLogLevel 设置为 2
我们的 mod_rewrite 规则的未修改版本位于:https ://webmasters.stackexchange.com/questions/4237/url-rewritten-pages-take-much-longer-to-load