Apache Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsSystem AdministrationApache Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 29th, 2001, 03:45 PM
RavaGe RavaGe is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 10 RavaGe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
ReWriteRule Misbehaving

I've got an extremely simple ReWriteRule in an .htaccess file:

ReWriteEngine On
ReWriteBase /
RewriteRule ^(.*) index.html

ReWriteLog (level 9) (activated in httpd.conf) returns the following:

add path-info postfix: c:/html/www.bar.com/foo -> c:/html/www.bar.com/foo/
strip per-dir prefix: c:/html/www.bar.com/foo/ -> foo/
applying pattern '^(.*)' to uri 'foo/'
rewrite foo/ -> index.html
add per-dir prefix: index.html -> c:/html/www.bar.com/index.html
add per-dir prefix: c:/html/www.bar.com/index.html -> c:/html/www.bar.com/c:/html/www.bar.com/index.html

Notice the last line. Shouldn't that be the culprit? I want to be able to type in www.bar.com/foo and end up at www.bar.com/index.html. At the moment all I'm getting is a 400 Invalid Request. Please note: I'm trying to find a solution for .htaccess and not for httpd.conf.

Thank You.

Last edited by RavaGe : November 29th, 2001 at 03:47 PM.

Reply With Quote
  #2  
Old November 29th, 2001, 04:16 PM
AlCapone's Avatar
AlCapone AlCapone is offline
Mobbing Gangster
Dev Shed Demi-God (4500 - 4999 posts)
 
Join Date: Sep 2001
Location: "Best City" 2002 and 2003- Melbourne, Australia
Posts: 4,913 AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level)AlCapone User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 5 h 36 m 31 sec
Reputation Power: 18
Send a message via ICQ to AlCapone Send a message via AIM to AlCapone Send a message via Yahoo to AlCapone
I am no master in rewrite, but couldn't you just use
RewriteEngine on
RewriteRule ^.* /index.html
of couse I do not see where you could use it since ALL of your requests will be forwarded to index.html
__________________
And you know I mean that.

Reply With Quote
  #3  
Old November 29th, 2001, 04:27 PM
RavaGe RavaGe is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 10 RavaGe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Tried that. Didn't work, unfortunately. Throws Apache into an endless loop. But when I alter the ReWriteRule to this:

RewriteEngine On
RewriteBase /
RewriteRule ^/(.*) index.html [L]

I get the following (ReWriteLog output):

strip per-dir prefix: c:/html/www.bar.com/foo -> foo
applying pattern '^/(.*)' to uri 'foo'
pass through c:/html/www.bar.com/foo

No good really, is it?

The idea behind this ReWriteRule is to have index.html (a PHP script) parse the REQUEST_URI and display content accordingly.

Last edited by RavaGe : November 29th, 2001 at 04:30 PM.

Reply With Quote
  #4  
Old November 29th, 2001, 04:30 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RewriteEngine on
# if request is index.html, last it
RewriteCond %{REQUEST_URI} ^/index\.html$
RewriteRule ^(.+) - [L]
# else if request is not a dir in top uri
RewriteCond %{REQUEST_URI} ^/([A-Za-z0-9_\.]+)$
# external redirect to index.html
RewriteRule ^(.+) index.html [R,L]

Be sure to disable MultiViews if it's enabled.

Reply With Quote
  #5  
Old November 29th, 2001, 04:47 PM
RavaGe RavaGe is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 10 RavaGe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Dear FreeBSD,
I tried your suggestion and got the following two results:

when typing in www.bar.com/foo (<- no trailing slash) I get redirected to http://www.bar.com/c:/html/www.bar.com/index.html
and the ReWriteLog gives me:

strip per-dir prefix: c:/html/www.bar.com/foo -> foo
applying pattern '^(.+)' to uri 'foo'
RewriteCond: input='/foo' pattern='^/index\.html$' => not-matched
strip per-dir prefix: c:/html/www.bar.com/foo -> foo
applying pattern '^(.+)' to uri 'foo'
RewriteCond: input='/foo' pattern='^/([A-Za-z0-9_\.]+)$' => matched
rewrite foo -> index.html
add per-dir prefix: index.html -> c:/html/www.bar.com/index.html
explicitly forcing redirect with http://www.bar.com/c:/html/www.bar.com/index.html
escaping http://www.bar.com/c:/html/www.bar.com/index.html for redirect
redirect to http://www.bar.com/c:/html/www.bar.com/index.html [REDIRECT/302]

If I type in the same URL but with a trailing slash then I get this:

add path-info postfix: c:/html/www.bar.com/foo -> c:/html/www.bar.com/foo/
strip per-dir prefix: c:/html/www.bar.com/foo/ -> foo/
applying pattern '^(.+)' to uri 'foo/'
RewriteCond: input='/foo/' pattern='^/index\.html$' => not-matched
add path-info postfix: c:/html/www.bar.com/foo -> c:/html/www.bar.com/foo/
strip per-dir prefix: c:/html/www.bar.com/foo/ -> foo/
applying pattern '^(.+)' to uri 'foo/'
RewriteCond: input='/foo/' pattern='^/([A-Za-z0-9_\.]+)$' => not-matched
pass through c:/html/www.bar.com/foo

Neither of them are working And yes, MultiViews are disabled. Figured that one out after reading some of your other messages. Thanks for the help.

Last edited by RavaGe : November 29th, 2001 at 04:51 PM.

Reply With Quote
  #6  
Old November 29th, 2001, 05:18 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Change this line RewriteRule ^(.+) index.html [R,L] to RewriteRule ^(.+) http://www.bar.com/index.html [R,L]

Like I always said, when doing internal redirection, always use /full/server/path/to/index.html. For external, use full URL.

>> RewriteCond: input='/foo/' pattern='^/([A-Za-z0-9_\.]+)$' => not-matched

As you can see, the pattern (/foo/) doesn't match, so pass-thru. Since you haven't told us what to do when requesting an index.html in a subdir, so my current condition skips those and pass-thru as well.

Last edited by freebsd : November 29th, 2001 at 05:22 PM.

Reply With Quote
  #7  
Old November 29th, 2001, 07:11 PM
RavaGe RavaGe is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 10 RavaGe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Definately need an internal redirect And what point is there in defining the full path ("always use /full/server/path/to/index.html") when it's in a .htaccess file and the ReWriteBase is / ?

I want *everything* to redirect to www.bar.com/index.html, including any possible www.bar.com/foo/index.html URLs.

I'm gonna play around with it a little more but I'm having a hard time. Maybe you have some more helpful suggestions?

Thanks a bunch!

Reply With Quote
  #8  
Old November 29th, 2001, 07:37 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> Definately need an internal redirect

Definitely NO. You need external redirect.

>> what point is there in defining the full path

So Apache knows the exact path without searching (waste of resource). On win32, it is possible that mod_rewrite doesn't work the same way as it should on UNIX.

>> when it's in a .htaccess file and the ReWriteBase is /

Your situation shouldn't be using RewriteBase in the first place. Use it only if your top uri is not beginning with /.

>> including any possible www.bar.com/foo/index.html

Then remove the 2nd condition and change the 2nd rewriterule to use full URL.

Reply With Quote
  #9  
Old November 29th, 2001, 07:49 PM
RavaGe RavaGe is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 10 RavaGe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> Definitely NO. You need external redirect.

An external redirect will always show www.bar.com/index.html, regardless of what I type in as an URL, right? I.e. if I type http://www.bar.com/foo/junk/ the browser will switch to www.bar.com/index.html.

I already got it to work on my hosting service's Linux box with .htaccess. It excludes the directory /images (duh - need to load html images ) but everything else is forwarded to /index.php. The code is:

RewriteEngine On
RewriteBase /
RewriteRule ^images(.*) images$1 [L]
RewriteRule ^(.*) index.php

With the exception of the URIs beginning with images everything lands at /index.php but without people seeing it. You can type www.bar.com/page/action/ and it will seem like a fully valid directory. What it's actually doing is the equivalent of /index.php?var1=page&var2=action. Index.php parses the URI internally.

Everything I've stated so far works.

My problem is merely trying to replicate these server setting on my WAMP installation. It'd make me the happiest man in the world

Reply With Quote
  #10  
Old November 29th, 2001, 11:29 PM
freebsd freebsd is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jan 2001
Posts: 5 freebsd User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
>> ...regardless of what I type in as an URL, right?

Correct.

>> everything else is forwarded to /index.php

There was no indication (with static index.html) from your original post that you acutally want search engine-friendly URL appropach.

>> www.bar.com/foo and end up at www.bar.com/index.html

That's external redirection.

>> RewriteRule ^(.*) index.php

This doesn't pass any query_string to index.php, thus useless.

>> What it's actually doing is the equivalent of /index.php?var1=page&var2=action. Index.php parses the URI internally

Now this finally looked like a REAL question. Your original sample using index.html was somthing totally different. When you want to redirect to a page, then without further processing, you would use external redirection approach. To do additional works like PHP parsing, you need internal redirection.
As I said, RewriteBase doesn't always fit every situation depending on your hosting setup. For your home server, try something like so:

RewriteEngine On
RewriteRule ^images(.*) - [PT,L]
RewriteRule ^index.php$ - [L]
RewriteRule ^XXX /full/server/path/to/index.php?YYY [T=application/x-httpd-php,L]

What to insert to replace XXX and YYY is left for you to utilitize the search feature here, since it has been asked and answered dozen times per day.

Reply With Quote
  #11  
Old December 6th, 2001, 11:04 AM
RavaGe RavaGe is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2001
Posts: 10 RavaGe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
This is what I have now in my httpd.conf:

<VirtualHost *>
DocumentRoot c:/html/www.bla.com
ServerName www.bla.me

ReWriteEngine On
RewriteRule ^/images(.*) - [L]
RewriteRule ^/php(.*) - [L]
RewriteRule ^/(.*) /index.php [L]
</VirtualHost>

And it works! The line with /php in it was necessary because otherwise it sent Apache into an endless loop, probably because I have an alias set for '/php/' to 'c:/php/php.exe'. Is there a better way of solving this problem? Other than that, all is working as hoped. Thank you very much for your assistance.

I still don't know why the solution I have for the .htaccess on my provider's server won't work on my local dev though.

Reply With Quote
Reply

Viewing: Dev Shed ForumsSystem AdministrationApache Development > ReWriteRule Misbehaving


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT