Forum Moderators: phranque

Message Too Old, No Replies

I write a REWRITE rule, but apache REDIRECT me.

         

imxxy

3:55 am on Jun 14, 2010 (gmt 0)

10+ Year Member


<VirtualHost *:80>
ServerName www.eg.com
DocumentRoot "e:/wamp/www/eg"
RewriteEngine On
RewriteRule ^/(\w+)course http://www.eg.com/html/$1course
</VirtualHost>

I want to rewrite http://www.eg.com/html/engcourse/ to http://www.eg.com/engcourse/

There are two problems:
1."RewriteRule ^/(\w+)course /html/$1course"
will couse a redirect loop.
I have to use RewriteRule ^/(\w+)peixun http://www.eg.com/html/$1course

2.Firebug tell that server send http header like this:
Location: http://www.eg.com/engcourse/
and my redirect to http://www.eg.com/engcourse/
I want to rewrite it but not redirect.
I've add [L] after my rule, but it didn't work.

[1][[b]edited by[/b]: imxxy at 4:01 am (utc) on Jun 14, 2010][/1]

imxxy

3:58 am on Jun 14, 2010 (gmt 0)

10+ Year Member



Please help me, thx!

g1smd

5:53 am on Jun 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I want to rewrite http://www.example.com/html/engcourse/ to http://www.example.com/engcourse/

Which one of those is the URL that you want users to see and use, and which is the internal filepath where the content resides?

If you want to rewrite this, the URL path goes on the left in the RegEx pattern, and the physical internal filepath where the content resides goes on the right without a domain name.

By including a domain name, you have created a 302 redirect. Omit the domain name.

You must also add the [L] flag.

The good news is this sort of rewrite question is asked several times every month and there are hundreds of prior examples, with very full explanations as to how it all works, right here in this forum.

You should add a preceding RewriteCond looking at REQUEST_URI and matching "not the rewritten path" so that the rule does not loop.

imxxy

8:25 am on Jun 14, 2010 (gmt 0)

10+ Year Member



I want my visitors see http://www.example.com/engcourse/ and the real path is http://www.example.com/html/engcourse/
My rule is:
RewriteEngine On
RewriteRule ^/(\w+)course /html/$1course [L]
But when I visit /engcourse it course a redirect loop:
/diannaopeixun/index.php/
/diannaopeixun/index.php/index.php/
/diannaopeixun/index.php/index.php/index.php/
...
It's very strange, but if I add my domain at the right side, it performed ok with a redirect(I want a rewrite).

jdMorgan

12:58 pm on Jun 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I want my visitors see http://www.example.com/engcourse/ and the real path is http://www.example.com/html/engcourse/

No. Don't confuse URLs with filepaths. The 'real path' is /html/engcourse/ -- This is a filepath relative to the server root, not a URL.

In addition, you missed an important bit of advice already posted above:

RewriteCond %{REQUEST_URI} !^/html/\w+course/
RewriteRule ^/(\w+)course/ /html/$1course/ [L]


Jim

g1smd

6:23 pm on Jun 14, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Yes, the preceding RewriteCond that I mentioned above is vital to the correct operation. :)