0

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.stackexchange.com/questions/4237/url-rewritten-pages-take-much-longer-to-load

Community
  • 1
  • 1
siliconpi
  • 8,105
  • 18
  • 69
  • 107

1 Answers1

0

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]
Ben
  • 3,922
  • 1
  • 22
  • 21
  • Hi @Ben - can you have a look at the edit - I dont think the changes worked properly – siliconpi Dec 02 '10 at 13:00
  • Those don't appear to be errors, and looking like its successfully passing them through to abcd/browse.php, what's happening on the browser end? – Ben Dec 02 '10 at 17:46
  • Hi @Ben - it gives a "Bad Request Your browser sent a request that this server could not understand." for both the URLs mentioned in Edit1 – siliconpi Dec 03 '10 at 06:22
  • Hi @Ben - there was an error in your proposed solution - it should be like: RewriteRule ^/abcd/.*/codelibrary/(.*)$ /abcd/codelibrary/$1 [L] [Note the / _before_ the abcd/] Can you revise the answer so that I can accept it? – siliconpi Dec 08 '10 at 11:48