Solved

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

Posted on 2006-10-30
20
837 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
ports for sccm 2012 1 110
PHP Apache application gives "Forbidden" message 5 82
Web Reply Form - PHP with Upload 4 87
web server dns redirect 5 74
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
If you are running a LAMP infrastructure, this little code snippet is very helpful if you are serving lots of HTML, JavaScript and CSS-related information. The mod_deflate module, which is part of the Apache 2.2 application, provides the DEFLATE…

752 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