PDA

View Full Version : RewriteEngine Issues


acslater323
10-27-2006, 07:30 PM
I know this is supposed to be really easy, but for some reason, my server keeps throwing an Internal Server Error when I add this to my .htaccess file at the root:

RewriteEngine on
RewriteRule !\.(gif|jpg|png|css)$ /home/content/a/b/c/abc123/html/index.php


Where abc123 is my username on my GoDaddy account.

I know GoDaddy leaves something to be desired when it comes to fancy stuff like this, but I've read all over the place, including GoDaddy's FAQs page that mod_rewrites are possible on their server.

Any ideas? I got an authentication script to work okay. Is there some issue with this syntax? I got it off of A List Apart.

Any help would be appreciated. Thanks.

corey84
10-27-2006, 09:37 PM
if thats all you have in your .htaccess it wont work you need to add some coditions

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite\.com [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} ^http://.*$
RewriteRule \.(jpe?g|gif|bmp|png)$ /index.php [L]


this comes from this site

http://www.yourhtmlsource.com/sitemanagement/bandwidththeft.html#lockingthedoor

acslater323
10-29-2006, 12:44 PM
Cool! Thanks a lot for that link. That was a huge help. What I'm trying to do is match any string that doesn't end in .jpg, .gif, or .css and redirect it to /index.php.

Anyone know how to do that?

This:

RewriteRule ^/.+!(\.gif|\.jpe?g|\.css)/$ /index.php

doesn't work. Any ideas?

acslater323
10-29-2006, 01:03 PM
I can't even get this to work..

RewriteEngine On
RewriteRule ^([a-z])/$ /index.php

What's wrong with my regex?

erisco
10-30-2006, 04:45 PM
Why would you want to do that? But okay, try this:

RewriteEngine On
RewriteRule ([a-zA-Z]*)/$ /index.php

acslater323
10-30-2006, 09:12 PM
Hi, Erisco,

Thanks for your help. Didn't seem to work, though. None of my pages get get rewritten. What I'm trying to do is a slick URL rewriting technique that I found on A List Apart (http://www.alistapart.com/articles/succeed/). Basically the idea is that every page gets passed to index.php, and then that file explodes the URL into an array (delimited by /, of course). Based on the contents in that array, the body of the page figures out which content to include.

I think it's a lot easier to do it that way than to add a rewrite rule every time you create a page.

Anyway.. any other ideas on my regex? I thought the URL part of the rewriterule had to begin with ^ and end with $...

erisco
10-30-2006, 09:24 PM
It doesn't have to start or end with anything acslater323, so long as it remains a valid RE.

With the rewrite rule I have supplied, entering anything from

http://www.example.com/ajdkfjskfjskgfsd/

to

http://www.example.com/coolfluffypillows/

Will both be rewritten to index.php. If you want something that can be broken up, and by that are you taking in any GET data? Or are you using the request uri variable?

RewriteEngine On
RewriteRule ([a-zA-Z0-9\.\-\_]*/)*$ /index.php

That'll rewrite anything from

http://www.example.com/a/b/c/d/e/f/g/h/i/j/k/

to

http://www.example.com/dsfajk45t9fgd-_.sfgjsd.-_/

to index.php. Now if you are wanting to send the thing through GET data, try this:

RewriteEngine On
RewriteRule ([a-zA-Z0-9\.\-\_]*/)*$ /index.php?uri=$1

I didn't read the article :P So I am not sure how they want you to set it up.. exactly.

acslater323
10-31-2006, 02:36 PM
I appreciate your continuted help on this, ericso. I haven't been able to turn up any advice in any other forums.

This:

RewriteEngine On
RewriteRule ([a-zA-Z0-9\.\-\_]*/)*$ /index.php

returned an internal server error for me. When I put the ^ in front of it, the error was gone, but no rewriting got done.

If you don't mind, could you take a quick look at the article? The code he provides didn't work, but I'm hoping I can find someone like you to tell me another way. :)

Thanks again for all your help.

corey84
10-31-2006, 04:16 PM
this rule works fine on my server

RewriteEngine on
RewriteRule !\.(gif|jpg|png|css)$ index.php


what you should do is this make a file called info.php and add this to it

phpinfo();

then go to that file in your browser scroll down till you see the heading apache2handler and under loaded modules check that mod_rewrite is loaded

acslater323
10-31-2006, 08:11 PM
Interesting. The phpinfo output did not have an apache2handler header anywhere.

I'm thinking that the mod_rewrite is enabled because it works when I do a simple rewrite rule like this:

RewriteEngine on
RewriteRule ^example/$ /index.php

so that's why I was questioning my regex.

Thanks for testing it on your server. I think that's a pretty good indication that GoDaddy does not, despite its claims, fully support mod_rewrite.