Forum Moderators: phranque

Message Too Old, No Replies

Mod_rewrite - Flustrated guy

For the past several hours I've been trying to make this mod_rewrite

         

stormshield

6:13 pm on Jan 9, 2006 (gmt 0)

10+ Year Member



Hi,

For the past several hours (I lost sense of time:)) I've been trying to make this mod_rewrite thing work - with no result!:(

After creating ".htaccess"(at first it was .txt extension but later I changed it) I chose the simpliest code there was:

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^index.htm$ index.php[L]

It should convert index.php to index.htm, am I right?
But it doesn't ...:(

I have no idea what may be wrong:
- I checked phpinfo() and there is mod_rewrite module
- the "htaccess "file is in the same directory as the file.
What can be wrong? Maybe I messed something up with ".htaccess"?
BTW, is it alright if in the extension row in Total Commander there is a blank space instead of "htaccess"?

I appreciate any suggestions
Marcin

MichaelBluejay

10:06 pm on Jan 9, 2006 (gmt 0)

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



You've got it backwards. This will grab requests form </index.htm> and redirect them to </index.php>.

I'm pretty sure you also want to add a space before the [L].

To assist in troubleshooting, change the [L] to [R=301,L]. That will cause the address bar to change to the new url, so you can see whether your command even fired or not.

stormshield

2:29 pm on Jan 10, 2006 (gmt 0)

10+ Year Member



MichaelBluejay - many thanks for your reply, but
unfortunetely it doesn't work:(

I put [R=301,L]instead of L and no troubleshooting appeared...

hm... I pretty sure that the sever just doesn't "see" the file, because this code doesn't work either:

ErrorDocument 404 index.htm

It should view the index.htm when a file doesn't exist, or is this code faulty, as well?

If somebody's got an idea, don't hesitate to post it.

Regards
Marcin

twist

3:00 pm on Jan 10, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you have frontpage extensions on your account?

Is your account php or asp?

Does your account come with a prebuilt htaccess file?

Send an email to your host if you don't know any of the above answers.

If your on a shared server, look around at other accounts and see how they have theirs setup.

stormshield

3:18 pm on Jan 10, 2006 (gmt 0)

10+ Year Member



>Do you have frontpage extensions on your account?
No, I don't think so

>Is your account php or asp?
php

Does your account come with a prebuilt htaccess file?

> I don't know that either, but I assume that in such case all directories would be affacted by one .htaccess only? Tell me something more, please.

The server I'm using is actually my father's and it's operated by some guy he employs... He is usally quite busy and in addiction he is paid for every hour he works so I try to keep it to minimum, you know :-)

MichaelBluejay

2:36 am on Jan 11, 2006 (gmt 0)

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



I put [R=301,L]instead of L and no troubleshooting appeared...

Yes, it did. If the url didn't change at all then that's telling you that your code didn't even try to execute, rather than that it was executing wrong.

Let's make sure your server is even finding your .htaccess file. Open that up and put some garbage in it, just smack the keyboard. Save it and then try to load any page on your site. You ought to get an Internal Server Error page. If your page loads correctly then your server isn't even seeing your .htaccess file.

If adding the junk brings your server down, that's good, because you know your server is seeing the file and trying to run it, and from there we can proceed to trying to fix your code.

Key_Master

2:56 am on Jan 11, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Check your httpd.conf file for the AccessFileName [httpd.apache.org] directive.

It might be named something other than .htaccess.

stormshield

7:24 am on Jan 11, 2006 (gmt 0)

10+ Year Member



MichaelBluejay :Yeah... it looks like the sever simply doesn't find it..

So where do I find the httpd.conf? in the root?

Thx guys

MichaelBluejay

11:57 am on Jan 11, 2006 (gmt 0)

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



I think it's really, really unlikely that your server is set up to NOT look for .htaccess. First make absolutely certain that your .htaccess file is named correctly, starting with a period, two c's, two s's, and no trailing period or extension.

Failing that, I suggest contacting your webhost. If they won't help you, get another host. If you have to pull teeth to get the server to see your .htaccess file and Support can't help you then you don't want to host with those guys.

According to an article I found with Google, httpd.conf is usually in /etc/, but it's not there on my server. I couldn't find it anywhere on my server. Then again, I don't need to -- and I doubt that you need to, either.

Key_Master

3:20 am on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is definately a setting in your httpd.conf file that is causing the problem. Either the AccessFileName is pointing to a name other than .htaccess or there is a "AllowOveride None" in the directory directives in the virtual host settings for that domain.

I'd advise you to contact your host and ask them to reconfigure it for you.

MichaelBluejay

4:23 am on Jan 12, 2006 (gmt 0)

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



I would hesitate to say that httpd.conf is "definitely" the problem. It could easily be a misspelled .htaccess file. Also, the .htaccess file could be in the wrong location. Make sure it's in the same directory as your main index.html file.

jd01

11:46 am on Jan 12, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



How about trying a simple test?

#Options +FollowSymLinks
RewriteEngine On
RewriteRule ^test\.html$ http://example.com/index.php [R=301,L]

Copy and paste the above to your .htaccess (change example.com to yoursite.com), then try to open yoursite.com/test.html in your browser. If you get to index.php, everything works and your problem is a caching issue. If you are not redirected or receive an error, try uncommenting the first line (removing the #), empty your cache and try again.

My guess is it is one of the above, or as suggested before AllowOverride in the httpd.conf file is set to 'none'. (If you need to have this changed, FileInfo is usually a better choice for security than all).

Please, let us know.

Hope this helps.

Justin

stormshield

2:24 pm on Jan 12, 2006 (gmt 0)

10+ Year Member



My host has fixed the problem and it seems to be OK now.

Thanks guys for all the advice, you helped a lot.