...

View Full Version : Script working on one server, error on another



b_hole
06-12-2007, 07:22 AM
Hi,

I wrote a little .htaccess file, working great in 2-3 websites I have.
Unfortunately, it causes a 500 Internal Server Error in 2 other websites. I think the problem might relate to authorization somehow, although I'm not sure.

Here's the complete .htaccess file:

RewriteEngine on
RewriteBase /
ReWriteRule \.htaccess [F]
RewriteRule ^([a-zA-Z\-/]+)/([a-zA-Z\-]+)/?$ index.php?parent=$1&url=$2 # <- problematic line, removing it solves the error
RewriteRule ^([a-zA-Z\-]+)/?$ index.php?url=$1

What can cause this error? Should I add something to php.ini, or to the .htaccess itself?


Thanks a lot.

_Aerospace_Eng_
06-12-2007, 07:32 AM
Do you have access to the server meaning can you edit the httpd.conf file? Some servers don't load the rewrite_module which might cause your file to give the 500 error.

b_hole
06-12-2007, 07:56 AM
Yes, I do. Where can I find this file? I looked at my FTP server, but no luck. Should I create it?

BTW, as I wrote in the code before - removing the one before last line in the code fixes the error, but of course that's not the solution, because then the file doesn't do its purpose.

_Aerospace_Eng_
06-12-2007, 08:06 AM
Its not something you can really create. Its not going to be on your main site. To enable this you will need to have physical access to the server itself meaning the computer that hosts your site. If you don't have this then I think you are out of luck unless you convince your webhost to enable the mod_rewrite module. I guess the question at hand is are you running your own servers or are you on a shared hosting plan?

b_hole
06-12-2007, 08:28 AM
The problem occurs on my websites hosted in Godaddy's shared hosting.
The websites where this code works fine are hosted in Godaddy's virtual dedicated server.

That means my only solution is to contact Godaddy?

b_hole
06-12-2007, 09:11 AM
_Aerospace_Eng_, thanks a lot for your help so far, but I don't think this is the problem (http://help.godaddy.com/article.php?article_id=899). Maybe something else?

_Aerospace_Eng_
06-12-2007, 09:32 AM
Hmm guess that rules that out. Try this

RewriteEngine on
RewriteBase /
ReWriteRule \.htaccess [F]
RewriteRule ^(.*)/(.*)/?$ index.php?parent=$1&url=$2
RewriteRule ^(.*)/?$ index.php?url=$1
I'm guessing you are wanting /somethinghere/somethingelsehere to rewrite to index.php?parent=somethinghere&url=somethingelsehere

b_hole
06-12-2007, 09:48 AM
What almost do the trick. The problem (a big one) is that it doesn't display images located in sub-directories.
What do you think about this one:

RewriteEngine on
RewriteBase /
ReWriteRule \.htaccess [F]
RewriteRule ^([a-zA-Z\-\/]+)/([a-zA-Z\-]+)/?$ index.php?parent=$1&url=$2
RewriteRule ^([a-zA-Z\-]+)/?$ index.php?url=$1A very small change to the original I posted, but in a (superficial) quick test seems to work.
UPDATE: that's not working properly either. this existing page: www.mydomain.com/dir-a/dir-b - not working (I'm referred to 404 not found).

So I guess we're back to square one. Any ideas?

_Aerospace_Eng_
06-12-2007, 10:07 AM
Looks fine to me. If it works it works.

b_hole
06-12-2007, 10:33 AM
See my update to my previous post. The code isn't working properly.

_Aerospace_Eng_
06-12-2007, 10:38 AM
Post your code for index.php including php.

b_hole
06-12-2007, 12:09 PM
I don't see how index.php plays a role in this issue, but lets say it only print the values of $url and $parent.

Just to make myself clear: this URL works fine:
www.mydomain.com/dir-a
But in deeper URLs I get the not-found error:
www.mydomain.com/dir-a/dir-b

_Aerospace_Eng_
06-12-2007, 07:09 PM
This will work if none of the directories have numbers in them.

RewriteBase /
ReWriteRule \.htaccess [F]
RewriteRule ^([a-zA-Z]+)/([a-zA-Z]+)/?$ /index.php?parent=$1&url=$2
RewriteRule ^([a-zA-Z]+)/?$ /index.php?url=$1

mr e
06-12-2007, 07:19 PM
In your last code, it looks like it's the \/ (backslash slash) in the second rule that's causing it to not work as expected

Aerospace's example should work, I amended his to support hyphens and numbers


RewriteEngine on
RewriteBase /
ReWriteRule \.htaccess [F]
RewriteRule ^([a-zA-Z0-9\-]+)/([a-zA-Z0-9\-]+)/?$ index.php?parent=$1&url=$2
RewriteRule ^([a-zA-Z0-9\-]+)/?$ index.php?url=$1

b_hole
06-13-2007, 09:19 AM
Thanks a lot, both of you :)

2 questions:
1. What the [F] means?
2. What this line means?

#IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*

_Aerospace_Eng_
06-13-2007, 09:33 AM
The F stands for forbidden. The second line is usually there if your server has the Frontpage Server Extension enabled.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum