Please help with RewriteEngine in htaccess file

Problems with the Windows version of XAMPP, questions, comments, and anything related.

Re: Please help with RewriteEngine in htaccess file

Postby Wiedmann » 26. January 2009 23:57

That suggestion still produced a 404 error only this time it could not locate the folders in the P:\website\upload\ folder instead of the P:\website\upload\slush folder

Well, you are making something wrong...

With the above config, you can access the file "P:\website\upload\slush\sub1\test.html" without any problems with the URI "http://localhost/slush/sub2/test.html". (and that was the question)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Please help with RewriteEngine in htaccess file

Postby Izzy » 27. January 2009 01:42

Wiedmann wrote:So you need:
RewriteEngine On
RewriteBase /slush
RewriteRule ^sub/(.*)$ sub2/$1

In your ".htaccess" in "P:\website\upload"...


Well, you are making something wrong...

With the above config, you can access the file "P:\website\upload\slush\sub1\test.html" without any problems with the URI "http://localhost/slush/sub2/test.html". (and that was the question)

But that was not the question and a rewrite to sub2 when the folder to rewrite to is sub1 in the tree, which does not exist, will give a 404 error - it still gives a 404 even if the sub1 folder exists, see down below.
Seymour Clufley Question wrote:...so the goal is simple: to change a URL like this:
http://www.mysite.com/sub/test.html
to this:

http://www.mysite.com/sub2/test.html



So based on your "wrong" question, here is my "wrong" config which is based on your "wrong" config.
(I have substituted my own DocumentRoot which should make no difference to the outcome).
Perhaps these "wrong" configs can be corrected so it will not produce a 404 error:

Alias in httpd-xampp.conf (see down below) as was posted:
Code: Select all
Alias /slush "C:/xampp1/htdocs"
<Directory "C:/xampp1/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>

.htaccess in C:/xampp1/htdocs
Code: Select all
RewriteEngine On
RewriteBase /slush
RewriteRule ^sub/(.*)$ sub2/$1

Tree:
"C:\xampp1\htdocs\slush\sub1\test.html"

URI
"http://localhost/slush/sub2/test.html"

Log:
"[error] [client 127.0.0.1] File does not exist: C:/xampp1/htdocs/sub2"


Now using the OP's question and some slight adjustment on your config:
Change tree "slush\sub1" to "slush\sub2"

URI
"http://localhost/slush/sub2/test.html"

Log:
"error] [client 127.0.0.1] File does not exist: C:/xampp1/htdocs/sub2"

Change URI to "http://localhost/sub/test.html"
Log
"[error] [client 127.0.0.1] File does not exist: C:/xampp1/htdocs/sub"

Same result with the Alias inside the <IfModule alias_module> directive in the httpd-xampp.conf or in the httpd.conf or even no Alias at all and of course, browser's cache deleted after each attempt.

Did you test your config before posting and if so did it give a 404 or did you get to the "\slush\sub2\test.html" or the erroneous \slush\sub1\test.html file?

BTW with the .htaccess placed in the \slush folder and all the rules and paths adjusted a 404 error still persist.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: Please help with RewriteEngine in htaccess file

Postby Wiedmann » 27. January 2009 07:56

With the above config, you can access the file "P:\website\upload\slush\sub1\test.html" without any problems with the URI "http://localhost/slush/sub2/test.html". (and that was the question)

But that was not the question

Sorry you are right (it's was really to late...), the sentence should be (and that is the rule doing):
With the above config, you can access the file "P:\website\upload\slush\sub2\test.html" without any problems with the URI "http://localhost/slush/sub/test.html".

(It's was really to late...)

Did you test your config before posting

Sure. (The post was a copy 'n paste from my working config)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Please help with RewriteEngine in htaccess file

Postby Izzy » 27. January 2009 09:35

Wiedmann wrote:With the above config, you can access the file "P:\website\upload\slush\sub1\test.html" without any problems with the URI "http://localhost/slush/sub2/test.html". (and that was the question)
This was not the original question of the OP, I did point out the difference in my last post but he did change it in a later post.
Izzy wrote:...so the goal is simple: to change a URL like this:
http://www.mysite.com/sub/test.html
to this:
http://www.mysite.com/sub2/test.html
Your URI
"http://localhost/slush/sub2/test.html" <this is not a rewritable URI as it is the correct URI to go to the test.html with or without a .htaccess rewrite rule.

This would be a true test of the .htaccess rewrite rule which is as the OP wanted in the first place:
http://localhost/sub/test.html

That URI with the .htaccess rewrite rule loads the test.html in the sub2 folder as expected.

The fault has been in the Alias, which I removed for this test and no problems.

If slush is in the URI then the Alias redirects the request to the doc root and there is no sub2 folder in the doc root, it is in the slush folder - the conflict starts here.

The Alias is parsed first followed by the .htaccess file so the Alias has passed the URI with a slush in it to doc root then the .htaccess takes the URI and tries to rewrite the URI to the sub2 folder which is not in the doc root, consequence is a file not found.



So now we have:
.htaccess in C:\xampp1\htdocs
RewriteEngine On
RewriteBase /slush
RewriteRule ^sub/(.*)$ sub2/$1

Tree
C:\xampp1\htdocs\slush\sub2\test.html

URI
http://localhost/sub/test.html

LOG
No error


Wiedmann wrote:Sorry you are right (it's was really to late...),
No need for apologies as we can all err when it is way past our bed time. ;)


Wiedmann wrote:the sentence should be (and that is the rule doing):
With the above config, you can access the file "P:\website\upload\slush\sub2\test.html" without any problems with the URI "http://localhost/slush/sub/test.html".
Your URI
http://localhost/slush/sub/test.html
Gives a 404 error.

http://localhost/sub/test.html
Does not give a 404 error.


Izzy wrote:Did you test your config before posting
Wiedmann wrote:Sure. (The post was a copy 'n paste from my working config)

Not a true test because as far as I can tell you did not include the Alias in the httpd.conf file into the equation, which would have produced the 404 errors.


This is the erroneous Alias and when removed the rule works, when it is inserted the URIs return error 404:
Code: Select all
Alias /slush "C:/xampp1/htdocs"
<Directory "C:/xampp1/htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>


@Seymour Clufley
At least for now, please use either an Alias or a rewrite rule but not both especially the above Alias directive and try and confirm exactly what you want to do and how you want to access your files.
Thanks.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: Please help with RewriteEngine in htaccess file

Postby Wiedmann » 27. January 2009 10:07

Not a true test because as far as I can tell you did not include the Alias in the httpd.conf file into the equation, which would have produced the 404 errors.

Well, what ever you think...

BTW: The test can only work, if the Alias is defined, because the ".htaccess" with the mod_rewrite rules is in the aliased directory. So you need both. (And this "problem" is really so simple, and a basic mod_rewrite.)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Please help with RewriteEngine in htaccess file

Postby Izzy » 27. January 2009 10:42

I repeat, all the test with the .htaccess in the doc root except the last test.

1. Using the Alias and the URI http://localhost/slush/sub/test.html gives a 404 error.

2. Using the Alias and the URI http://localhost/slush/sub2/test.html gives a 404 error - direct URI

3, Using the Alias and the URI http://localhost/sub/test.html gives a 404 error.

4. No Alias and the URI http://localhost/slush/sub/test.html gives a 404 error.

5. No Alias and the URI http://localhost/slush/sub2/test.html gives NO 404 error - direct URI

6. No Alias and the URI http://localhost/sub/test.html gives NO 404 error - rewrite rule

7. No Alias and No .htaccess file and the URI http://localhost/slush/sub2/test.html gives NO 404 error - direct URI

So we agree to disagree that this problem is so simple and obvious, that using the Alias is in conflict with the .htaccess rewrite rule, at least in my comprehensive and thorough test.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: Please help with RewriteEngine in htaccess file

Postby Wiedmann » 27. January 2009 10:55

I repeat, all the test with the .htaccess in the doc root except the last test.

Maybe you repeat something, but not the correct things... ("sub2" is a subdiretory in the aliased directory ("P:/website/upload/sub2"), and must not exists in the normal document root. Also there must no subdirectory "slush" or "sub" in your normal DocumentRoot.
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Please help with RewriteEngine in htaccess file

Postby Izzy » 27. January 2009 11:37

I will test that out when I have more time and post what I find by using C:\website\upload as the web root folder and in the Alias directive.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: Please help with RewriteEngine in htaccess file

Postby Wiedmann » 27. January 2009 12:21

using C:\website\upload as the web root folder

"C:\website\upload" is not the DocumentRoot. (so no interest to test this situation)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Please help with RewriteEngine in htaccess file

Postby Izzy » 27. January 2009 12:34

Wiedmann wrote:"C:\website\upload" is not the DocumentRoot. (so no interest to test this situation)
You may not have any interest in testing but I have as this quote still gives me doubts and needs to be tested thoroughly and not just accepted as being correct.
Wiedmann wrote:Maybe you repeat something, but not the correct things... ("sub2" is a subdiretory in the aliased directory ("P:/website/upload/sub2"), and must not exists in the normal document root. Also there must no subdirectory "slush" or "sub" in your normal DocumentRoot.
From what I see there is no physical slush sub directory anyway anywhere it is only referred to in the Alias Directive.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Re: Please help with RewriteEngine in htaccess file

Postby Wiedmann » 27. January 2009 13:07

From what I see there is no physical slush sub directory anyway anywhere

Correct. But you must have this directory:
Izzy wrote:No Alias and the URI http://localhost/slush/sub2/test.html gives NO 404 error - direct URI


but I have as this quote still gives me doubts

Well, I can't understand your problem with this basic thing:
- It's just a simple rewrite from "old to new" without any special (search the Apache doku for this example).
- And because the ".htaccess" is in an Alias dir, you have an additional "RewriteBase" Directive. (Without an Alias, there is no need for this directive)
Wiedmann
AF Moderator
 
Posts: 17102
Joined: 01. February 2004 12:38
Location: Stuttgart / Germany

Re: Please help with RewriteEngine in htaccess file

Postby Izzy » 27. January 2009 13:18

Correct. But you must have this directory:
Yes and that may well have been the only issue that was affecting this, that I had included a slush sub when in fact this should not have been the case and as I pointed out I need to test this in both the C:\website\upload scenario and in the C:\xampp\htdocs scenario, but it is late and I must not make mistakes because of it. ;)

It is a surprise to me that this fact of a slush sub was not pointed out many post back when it was obviously relevant to the issue of a 404 error.
Izzy
 
Posts: 3344
Joined: 25. April 2006 17:06

Previous

Return to XAMPP for Windows

Who is online

Users browsing this forum: No registered users and 77 guests