Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite (some rules work, some don't)

         

ayushchd

6:16 am on Jun 15, 2010 (gmt 0)

10+ Year Member



Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^hyperlite.co.uk
RewriteRule (.*) http://www.hyperlite.co.uk/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.hyperlite.co.uk/ [R=301,L]


The above rules work fine.

Howsoever, if I add the following line below this code, the new rule doesn't work, while the previous rules work

RewriteRule hyperlite_news.html$ news.php
[code][/code]


Please assist!

g1smd

7:03 am on Jun 15, 2010 (gmt 0)

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



As currently written your redirect rules cause a chain when the non-www index is requested. You can test that using Live HTTP Headers for Firefox.

You should swap the order of your "domain redirect" and "index redirect" so that the "index redirect" is first.

Add the [L] flag to the "news rewrite".

In what way does the "rewrite" not work?

ayushchd

7:05 am on Jun 15, 2010 (gmt 0)

10+ Year Member



I just wrote this :
Options +FollowSymLinks
RewriteEngine on

RewriteRule ^hyperlite_news\.html$ news.php

This rule gives me a 404..

Can you help?

ayushchd

7:05 am on Jun 15, 2010 (gmt 0)

10+ Year Member



I just wrote this :
Options +FollowSymLinks
RewriteEngine on

RewriteRule ^hyperlite_news\.html$ news.php

This rule gives me a 404..

Can you help?

g1smd

6:07 pm on Jun 15, 2010 (gmt 0)

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



You didn't add the [L] flag.

Presumably the news.php file doesn't exist, or the path to the news.php script isn't what you think it is.

ayushchd

4:09 am on Jun 15, 2010 (gmt 0)

10+ Year Member




System: The following 2 messages were spliced on to this thread from: http://www.webmasterworld.com/apache/4152700.htm [webmasterworld.com] by jdmorgan - 9:02 pm on Jun 15, 2010 (CDT -5)


Could anybody tell me how to test the following rewrite rules to confirm whether mod_rewrite is working or not?

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.co.uk
RewriteRule (.*) http://www.example.co.uk/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.example.co.uk/ [R=301,L]

What URL should I type in and which should be called for that URL? This is in a folder "testsite" on my server.

Thanks

[edited by: jdMorgan at 12:55 am (utc) on Jun 16, 2010]
[edit reason] Please use example.com only. [/edit]

jdMorgan

1:02 am on Jun 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your two rules are reversed. Put the index redirect first, followed by the hostname redirect.

You'd request www.example.co.uk/testsite/index to test the index redirect. Whether you can test the hostname canonicalization rule in a test subdirectory is doubtful (depends on the server configuration), but if so, then requesting example.co.uk/testsite/ would do it.

If you just want to test if mod_rewrite is working, then these rules are too complex. Use something like
 RewriteRule ^.*$ http://www.google.com/ [R=301,L] 

for a simple test.

Take that lesson forward. Do not try to test "a big gobbet of code" all at once. Add and test one rule at a time until you're very comfortable with this code.

Jim