Solved

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

Posted on 2006-10-30
20
829 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
Comment Utility
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
Comment Utility
yes, I tryied. It doesn't work either.....
0
 
LVL 15

Expert Comment

by:periwinkle
Comment Utility
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
 
LVL 1

Expert Comment

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

Expert Comment

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

Author Comment

by:syrma
Comment Utility
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
Comment Utility
Yup.  Not sure why that's not working... maybe some other rule over-riding it?
0
 
LVL 15

Expert Comment

by:periwinkle
Comment Utility
Is there any information in the error_log?
0
 
LVL 1

Expert Comment

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

Author Comment

by:syrma
Comment Utility
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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
LVL 2

Author Comment

by:syrma
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
And You added the slash to the second parameter of RewriteRule? If so - no more ideas currenty.
0
 
LVL 2

Author Comment

by:syrma
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Suggested Solutions

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
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…
This video discusses moving either the default database or any database to a new volume.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now