Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2006-10-30
20
Medium Priority
?
842 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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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 1000 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

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
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 …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…
Suggested Courses

730 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