Solved

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

Posted on 2006-10-30
20
833 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
  • 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
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

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). #…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

839 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