Forum Moderators: phranque

Message Too Old, No Replies

RewriteRule not work on ixwebhosting

         

John_SQ

2:16 pm on Apr 21, 2009 (gmt 0)

10+ Year Member



I Use ixwebhosting(bussiness plus win) hosting service
URL A: [mysite.cc...] works fine.
a 404 page loaded when I tried to rewrite the above url to URL B:http://www.mysite.cc/abc/hello-world/ base on the RewriteRule setting in .htaccess as follows, but this rewriterule works fine on my localhost hosting.
I mean:http://localhost/mysite/abc/hello-world/ can correct be loaded.
-------------------------------------
Options +FollowSymLinks
RewriteEngine on
RewriteRule ^abc/([-\w]+)/$ abc\.php?def=$1&%{QUERY_STRING} [L]
--------------------------------------
Have anybody meet this similar problem before? What can i do next to make it fixed?

Thanks
John

g1smd

8:28 pm on Apr 21, 2009 (gmt 0)

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



You want to rewrite URL http://example.com/abc/hello-world to fetch content from internal filepath at: /abc.php?def=hello-world ?

That should be quite easy. Does the original URL request actually use a {QUERY_STRING} here? Your example URL does not contain a query string. You'll need to create and use a backreference something like this:

RewriteRule  ^abc/([^/]+)/$  /abc.php?def=$1&%{QUERY_STRING} [L]

jdMorgan

2:54 am on Apr 22, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



It may just be an incompatibility in the regular-expressions libraries on the two machines.

If your (working) localhost is Apache 2.2 and the (non-working) server is and older version, then that would explain it: Older versions of Apache use the POSIX regular expressions usually bundled with the OS, while Apache 2.2 supports PCRE (PERL-Compatible Regular Expressions). So you'll have trouble using PCRE tokens like "\w" on older versions of Apache.

If g1smd's pattern above is not selective enough for your needs, then this should work on any version of Apache:


RewriteRule ^abc/([0-9a-z_\-]+)/$ /abc.php?def=$1 [NC,L]

Note that the [NC] flag makes the alphabetic character comparison case-insensitive. This may be preferable to using the longer pattern of "[0-9A-Za-z_\-]". It is faster, but it also allows a match on "/AbC/foo/".

Jim

John_SQ

6:57 am on Apr 22, 2009 (gmt 0)

10+ Year Member



Thank you very much for your kindly help,
I have tried both of your advice, but still not work.
whether should I do some other setting on ixwebhosting manage panel to make it support this url rewriterule?

Regards
John

John_SQ

4:47 am on Apr 27, 2009 (gmt 0)

10+ Year Member



Hi jdMorgan,g1smd

After switch the hosting to Linux platform, it can work well, Many Thanks for your kindly help.

Regards
John

g1smd

9:16 pm on Apr 27, 2009 (gmt 0)

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



*** I Use ixwebhosting(bussiness plus win) hosting service ***

I missed the clue in your original question that meant that your hosting was Windows IIS not Linux Apache. :)