httpd.conf and .htaccess question

XML, Perl, Python, and other languages can be discussed here, even if it isn't PHP (We might forgive you).

Moderator: General Moderators

Post Reply
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

httpd.conf and .htaccess question

Post by mydimension »

i am trying to use the mod_rewrite.c module to do some url rewriting for my site. i am doing this on my WinXP dev station. i know that what i am trying to do will most likely work on the server i eventually upload this to, but i would like to get it to work on my home comp as well. here is my quandry:

if i place these lines:

Code: Select all

RewriteEngine On
RewriteRule ^/news/(ї0-9]+) /news.php?$1
RewriteRule ^/profile/(їa-zA-Z0-9]+) /profile.php?$1
RewriteRule ^/forum/(ї0-9]+) /forum/forum.php?$1
RewriteRule ^/forum/thread/(ї0-9]+) /forum/thread.php?$1
into my httpd.conf file everything works fine. if i place them into a .htaccess file i get an internal server error. for this directory i have AllowOverride set to All so i don't believe it is an permission issue. any ideas would be much appreciated.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

is there something else in .htaccess that may cause the conflict?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

nope, those five lines are the onlt things in there
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

strange because (I know you don't want to hear this) it works on my box.
.htaccess is placed in you document-root-dir?
are there still other RewriteRules in your httpd.conf?
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

my version of Apache is 1.3.14. about the only thing that i could see making a huge difference is that the rewrite module is being loaded as a dll (modules/ApacheModuleRewrite.dll). not sure if the dll works differently then a hard coded module or not but just thought i would make that point. something else that might weigh in here is that i am using phpTriad (the PHP/MySQL/Apache installer), would you reccomend i do a complete reinstall doing each install my self?
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

You can't use .htaccess on Windows... Well so I heard.
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

Takuma, the reason people say that is because in the explorer interface you can't name a file with nothing before the "." but you can do it in a dos box.

i looked at my rewritelog and this is what i found:

Code: Select all

127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (2) init rewrite engine with requested uri /news/2
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (1) pass through /news/2
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (3) їper-dir g:/web page dev/cm/] add path-info postfix: g:/web page dev/cm/news.php -> g:/web page dev/cm/news.php/2
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (3) їper-dir g:/web page dev/cm/] strip per-dir prefix: g:/web page dev/cm/news.php/2 -> news.php/2
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (3) їper-dir g:/web page dev/cm/] applying pattern '^/news/(ї0-9]+)' to uri 'news.php/2'
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (3) їper-dir g:/web page dev/cm/] add path-info postfix: g:/web page dev/cm/news.php -> g:/web page dev/cm/news.php/2
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (3) їper-dir g:/web page dev/cm/] strip per-dir prefix: g:/web page dev/cm/news.php/2 -> news.php/2
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (3) їper-dir g:/web page dev/cm/] applying pattern '^/profile/(їa-zA-Z0-9]+)' to uri 'news.php/2'
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (3) їper-dir g:/web page dev/cm/] add path-info postfix: g:/web page dev/cm/news.php -> g:/web page dev/cm/news.php/2
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (3) їper-dir g:/web page dev/cm/] strip per-dir prefix: g:/web page dev/cm/news.php/2 -> news.php/2
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (3) їper-dir g:/web page dev/cm/] applying pattern '^/forum/(ї0-9]+)' to uri 'news.php/2'
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (3) їper-dir g:/web page dev/cm/] add path-info postfix: g:/web page dev/cm/news.php -> g:/web page dev/cm/news.php/2
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (3) їper-dir g:/web page dev/cm/] strip per-dir prefix: g:/web page dev/cm/news.php/2 -> news.php/2
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (3) їper-dir g:/web page dev/cm/] applying pattern '^/forum/thread/(ї0-9]+)' to uri 'news.php/2'
127.0.0.1 - - ї26/Sep/2002:00:20:38 -0400] їlocalhost/sid#5b5798]їrid#66a7d8/initial] (1) їper-dir g:/web page dev/cm/] pass through g:/web page dev/cm/news.php
keep in mind that g:/web page dev/cm/ is my DocumentRoot

it seems to be doing some weird matching and trying to apply the patterns to a directory instead of the url. and at the same time its making a url "news.php/2". im just stumpped as to why it is doing this in .htaccess yet it works fine httpd.conf.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I just added

Code: Select all

RewriteEngine On
RewriteRule /MSADC/(.*) http://www.gemal.dk/browserspy/accept.cgi їR,NC]
RewriteRule /scripts/(.*) http://scan.sygate.com:443/cgi-bin/probe/tcpscan.cgi їR,NC]
RewriteRule /_vti_bin/(.*) http://www.guninski.com/iis50shtml.html їR,NC]
RewriteRule /_mem_bin/(.*) http://cert.uni-stuttgart.de/archive/win-sec-ssc/2001/09/msg00024.html їR,NC]
RewriteRule /c/(.*) http://wetelephant.cotse.com/nettest.htm їR,NC]
RewriteRule /d/(.*) http://news.com.com/2009-1017-236684.html?legacy=cnet їR,NC]
to .htaccess on my box at home to get rid of some nimda-scanners (will not do it for long, only testing ;) ). There is a flag you have to set for full regular expression support, maybe ^ is in there.
take a look in the apache manual @'Run-time Configuration Directives'
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

well, ive made some headway. i did a complete reinstall of PHP, MySQL/Apache to the latest versions. my .htaccess now contains this:

Code: Select all

RewriteEngine on
RewriteRule ^news/(ї0-9]+) /news.php?$1
RewriteRule ^profile/(їa-zA-Z0-9]+) /profile.php?$1
RewriteRule ^forum/(ї0-9]+) /forum/forum.php?$1
RewriteRule ^forum/thread/(ї0-9]+) /forum/thread.php?$1
now i have run into a problem that could blam on the windows directory structure, ill explain.

the first rule redirects http://localhost/news/2 to http://localhost/news.php?2. however because i have a file named news.php the server goes directly to news.php and skips the rewrite rule.

the third rule works because there is no file named forum.php in the root directory.

insummary it appears that Apache or Windows (not sure which) looks up files using only the name of the file (that is without the extension. ie. looks for any file named news.* no matter what the requested files extension was) and the only time it does use the extension to find the file is when there is abiguity as which file was requested.

my question is now, how do you force Apache/Win32 to always use a files extension and not try to shortcut the system?
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

I think that's related to mod_negotiation.c but I do not understand neiter :?
f1nutter
Forum Contributor
Posts: 125
Joined: Wed Jun 05, 2002 12:08 pm
Location: London

Post by f1nutter »

Here's a thought. Doesn't the Rewrite rule go hand-in-hand with RewriteCond? Couldn't you use Redirect?

Takuma: You can use .htaccess in Windows. I'm using Apache on Win98 and it works a dream.[/quote]
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

well, i circumvented the problem by renaming problem files to rw_{whatever}.php. in this way a request to /news/2 cannot be confused with a request to /rw_news.php. thank you all for youe help. maybe in the future i will find a cleaner solution (like switching my desktop to linux!! :twisted:)
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

switching to linux is no escape, I tried this your example at my server, too. Same result.
I really would like to understand the name mangeling apache performs.
I know how to name files that they are found (page.html.en and so on) but I do not know how to force that only exact requests will be served :-S
User avatar
mydimension
Moderator
Posts: 531
Joined: Tue Apr 23, 2002 6:00 pm
Location: Lowell, MA USA
Contact:

Post by mydimension »

I DID IT!!!

volka, i went back and looked at the mod_negotiation.c documentation and found out it was because of the MultiViews Option. I disabled that and everything works now without renaming the files.

again, thank you SOOOooOO much for your help!!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

disabling MultiView completely is no option for me :(
I would like to disable it for certain mimetypes (script is NOT script.php)
but I'm glad you're happy ;)
Post Reply