Solved

Moving RewriteRule(s) from .htaccess to httpd.conf

Posted on 2006-10-30
20
841 Views
Last Modified: 2008-03-17
Hello,

Here is what I'm trying to do, unfortunately I can't make it working so far.
I have a bunch of .htaccess files for some vhosts which contain some RewriteRules.

Here for example I'll take the simplest one (this is the working example)

.htaccess:
------
             RewriteEngine On
             RewriteRule ^index.html$ /index.php
------

Now I want to move this in the httpd.conf so to take effect for all vhosts on the server.
I'm using Apache 2.0.52/Red Hat/mod_rewrite is loaded.
According to what I found in the documentation I added the slash (^/) and placed the rule inside a <directory>:
Here is what I have so far:

httpd.conf (not working)
-------------
<Directory "/var/www/vhosts">
            Options +FollowSymLinks
            AllowOverride None
            RewriteEngine On
            RewriteRule ^/index.html$ index.php
</Directory>
--------------

Here is my log:
--------------
212.***.***.*** - - [30/Oct/2006:10:52:45 --0600] [sampledomain.com/sid#94d43c8][rid#96d5948/initial] (3) [per-dir /var/www/vhosts/sampledomain.com/httpdocs/] strip per-dir prefix: /var/www/vhosts/sampledomain.com/httpdocs/index.html -> index.html
212.***.***.*** - - [30/Oct/2006:10:52:45 --0600] [sampledomain.com/sid#94d43c8][rid#96d5948/initial] (3) [per-dir /var/www/vhosts/sampledomain.com/httpdocs/] applying pattern '^/index.html$' to uri 'index.html'
212.***.***.*** - - [30/Oct/2006:10:52:45 --0600] [sampledomain.com/sid#94d43c8][rid#96d5948/initial] (1) [per-dir /var/www/vhosts/sampledomain.com/httpdocs/] pass through /var/www/vhosts/sampledomain.com/httpdocs/index.html

Do anybody has idea how to make this rule working inside the httpd.conf file and to be valid for all vhosts?

Thank you in advance.

0
Comment
Question by:syrma
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 9
  • 5
  • 4
  • +1
20 Comments
 
LVL 1

Expert Comment

by:FartingUncle
ID: 17835618
Have you tried _without_ the slash?

The line
     applying pattern '^/index.html$' to uri 'index.html'

implies that the slash isn't needed.
0
 
LVL 2

Author Comment

by:syrma
ID: 17835636
yes, I tryied. It doesn't work either.....
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 17835677
The preceding slash is an error - if you look in the logs, it it trying to match index.html to /index.html and failing.

Why not just use DirectoryIndex to say that index.php is the base page, though?
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 
LVL 1

Expert Comment

by:FartingUncle
ID: 17835791
What log messages do you get when the leading slash is removed?
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17835795
I guess it should be
RewriteRule ^index.html$ /index.php
0
 
LVL 2

Author Comment

by:syrma
ID: 17835828
Ok, thanks FartingUncle and Periwinkle.
I think I found something.
I have tryied without the slash multiple times, and it's still not working.
But just now I noticed that without the slash it's not writing anything in the log.
I'm not sure if this leads to anywhere.

As far as DirectoryIndex, the rule above is only an example, not an actual scenario.
But the problem I'm having right now is not in the rules themselves, but rather how to move them, that's why I used such example.

Thanks again. Any ideas?
0
 
LVL 1

Expert Comment

by:FartingUncle
ID: 17835838
Yup.  Not sure why that's not working... maybe some other rule over-riding it?
0
 
LVL 15

Expert Comment

by:periwinkle
ID: 17835841
Is there any information in the error_log?
0
 
LVL 1

Expert Comment

by:FartingUncle
ID: 17835843
(my response was to ravenpl's post)
0
 
LVL 2

Author Comment

by:syrma
ID: 17835887
I just checked the error_log, I have multiple of these:

[Mon Oct 30 12:21:13 2006] [warn] RSA server certificate CommonName (CN) `plesk' does NOT match server name!?
0
 
LVL 2

Author Comment

by:syrma
ID: 17835917
I'm sorry,
Ignore the last one, That's not related.
The error in the error_log was is not related with the question.
Nothing in the error_log about the mod_rewrite issue.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17835926
Well, that's toally different issue.
Your 'Servername www.domain.tls'
line must exacly match the ComonName from the certificate.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17835976
Note: rewrite rule expects to rewrite whole request url (hope i'm not wrong), therefore it has to rewrite the url to /something/...Have You tried
RewriteRule ^index.html$ /index.php [L]
where [L] means - don't try next rewriteRules on this url
0
 
LVL 2

Author Comment

by:syrma
ID: 17836050
ravenpl, thanks for response.
I just tryed with [L] - it's the same, not working and nothing in the log.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17836067
And You added the slash to the second parameter of RewriteRule? If so - no more ideas currenty.
0
 
LVL 2

Author Comment

by:syrma
ID: 17836100
Ok, my bad, after applying the [L] and no slash this is what I have in the log:

212.***.***.*** - - [30/Oct/2006:12:45:55 --0600] [sampledomain.com/sid#91233c8][rid#9324948/initial] (3) [per-dir /var/www/vhosts/] strip per-dir prefix: /var/www/vhosts/sampledomain.com/httpdocs/favicon.ico -> sampledomain.com/httpdocs/favicon.ico
212.***.***.*** - - [30/Oct/2006:12:45:55 --0600] [sampledomain.com/sid#91233c8][rid#9324948/initial] (3) [per-dir /var/www/vhosts/] applying pattern '^index.html$' to uri 'sampledomain.com/httpdocs/favicon.ico'
212.***.***.*** - - [30/Oct/2006:12:45:55 --0600] [sampledomain.com/sid#91233c8][rid#9324948/initial] (1) [per-dir /var/www/vhosts/] pass through /var/www/vhosts/sampledomain.com/httpdocs/favicon.ico

0
 
LVL 2

Author Comment

by:syrma
ID: 17836123
this is what I'm using in httpd.conf:

<Directory "/var/www/vhosts">
            Options +FollowSymLinks
            AllowOverride None
            RewriteEngine On
            RewriteRule ^index.html$ /index.php [L]
</Directory>

I'm not sure at all where this favicon.ico is coming from, as I don't remember to have it set anywhere.
0
 
LVL 2

Author Comment

by:syrma
ID: 17836184
Last log:

212.***.***.*** - - [30/Oct/2006:12:57:15 --0600] [sampledomain.com/sid#995c3c8][rid#9b5d898/initial] (3) [per-dir /var/www/vhosts/] strip per-dir prefix: /var/www/vhosts/sampledomain.com/httpdocs/index.html -> sampledomain.com/httpdocs/index.html
212.***.***.*** - - [30/Oct/2006:12:57:15 --0600] [sampledomain.com/sid#995c3c8][rid#9b5d898/initial] (3) [per-dir /var/www/vhosts/] applying pattern '^index.html$' to uri 'sampledomain.com/httpdocs/index.html'
212.***.***.*** - - [30/Oct/2006:12:57:15 --0600] [sampledomain.com/sid#995c3c8][rid#9b5d898/initial] (1) [per-dir /var/www/vhosts/] pass through /var/www/vhosts/sampledomain.com/httpdocs/index.html
0
 
LVL 43

Accepted Solution

by:
ravenpl earned 250 total points
ID: 17836369
Aah, seems more clear now. Is /var/www/vhosts contains more vhosts - Yes, it is. Try rule like follows
RewriteRule (.*)/index.html$ $1/index.php
it will redirect any index.html to index.php in any virtualHost (and subdirs) within /var/www/vhosts
0
 
LVL 2

Author Comment

by:syrma
ID: 17836525
ravenpl, thank you so much.
That was really it.
Now it's doing exactly what I need it to. Redirects all vhosts in the same way.

Thanks again :)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Hi, in this article I'm going to teach you how to run your own site, and how to let people in (without IP). I'll talk about and explain each step... :) By the way, everything in this Tutorial is completely free and legal. This article is for …
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question