|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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. |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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. |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
|||
|
|||
|
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! |
|
#8
|
|||
|
|||
|
>> 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. |
|
#9
|
|||
|
|||
|
>> 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 ![]() |
|
#10
|
|||
|
|||
|
>> ...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. |
|
#11
|
|||
|
|||
|
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. |
![]() |
| Viewing: Dev Shed Forums > System Administration > Apache Development > ReWriteRule Misbehaving |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|