Converting mod_rewrite rules in .htaccess to httpd.conf
I have a set of html files at: www.example.com and the "main site" (in beta) at: www.example.com/abcd/ (for which these mod_rewrite rules are needed)
The mod_rewrite rules run fine in a directory within .htaccess. I need to put them in httpd.conf:
The rules look like this in .htaccess:
RewriteEngine On
RewriteBase /abcd/
RewriteRule ^.*/codelibrary/(.*)$ codelibrary/$1 [L]
RewriteRule ^.*/in_upload/images/(.*)$ in_upload/images/$1 [L]
...
Copying the below into the httpd.conf file didnt work:
<VirtualHost *:80>
ServerAlias www.example.com
ServerAdmin nobody@example.com
DocumentRoot /var/www/html
ServerSignature On
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /abcd/
...
It gave an error:
RewriteBase: only valid in per-directory config files
Do I need to modify all rules like this?
RewriteRule ^.*/abcd/codelibrary/(.*)$ abcd/codelibrary/$1 [L]
RewriteRule ^.*/abcd/in_upload/images/(.*)$ abcd/in_upload/images/$1 [L]
Edit1
I tried to convert the following lines from:
...
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]
...
To:
...
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]
...
but I got errors as follows.
When I try accessing http://www.example.com/abcd/ins/Sustainability/282.html , I get the following error in the log:
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
When I try accessing http://www.example.com/abcd/ins.html , I get the following error in the log:
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
I've set RewriteLogLevel to 2
The unmodified version of our mod_rewrite rules are at: https://webmasters.stackex开发者_运维知识库change.com/questions/4237/url-rewritten-pages-take-much-longer-to-load
What is the purpose of the rewrite rules (i.e what are you trying to achieve)?
By the looks of the original in the .htaccess it was doing to redirect: www.example.com/abcd/anything/codelibrary/aaaa to www.example.com/abcd/codelibrary/aaaa
Same for in_upload/images too, Is this correct?
If so then this should work:
RewriteRule ^/abcd/.*/codelibrary/(.*)$ /abcd/codelibrary/$1 [L]
RewriteRule ^/abcd/.*/in_upload/images/(.*)$ /abcd/in_upload/images/$1 [L]
精彩评论