.htaccess file causing Server Error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

.htaccess file causing Server Error

Post by simonmlewis »

Hi

I am trying to work on Short Urls, so am changing settings to I can have a local url setup properly.
http://testingsite.local
Problem is it doesn't direct to the full URL, so I have added the HTACCESS file in there

Code: Select all

DirectoryIndex index.html index.htm index.php
order allow,deny
allow from all 
Options +FollowSymLinks
Options +Indexes
RewriteEngine On
RewriteRule ^$ index.php?page=home&menu=home [L]
And this immediately causes:
Server error!

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster.
I've setup the hosts file. So not sure what's causing it. any ideas?

EDIT: mod rewrite rule is loaded, according to PHP Info.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: .htaccess file causing Server Error

Post by Christopher »

Check the docs, but I think there are some configuration options you need to allow to have rewrite work. Check AllowOverride for things like AuthConfig. FileInfo, Options, etc.
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .htaccess file causing Server Error

Post by simonmlewis »

Sorry but you are talking greek to me.
Please if you could explain exactly what to look for, and where, and the setting things should be on, as I have not a clue.
I am trying to learn the mod rewrite, but until I can get this basic this running, I'm stuck.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: .htaccess file causing Server Error

Post by Christopher »

The problem may not be with your rewrite rules, it may be that your server dies on .htaccess files. You need to configure Apache first to allow you can set things in .htaccess files.
(#10850)
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .htaccess file causing Server Error

Post by simonmlewis »

Lovely - how?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: .htaccess file causing Server Error

Post by twinedev »

By changing settings in httpd.conf is one sure way. You have to remember, we do not already know how your server is currently set up and they can be set up tons of different ways.
Search documentation and then the file for settings of "AllowOverride" to see what they are set for.

Just because mod_rewrite is enabled, doesn't mean that other options/settings in .htaccess are not allowed.

Is this your own server setup? Are you trying to do this on a hosting plan somewhere?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .htaccess file causing Server Error

Post by simonmlewis »

I am trying to do this locally first. I use XAMPP for my Apache/PHP web site running.
I managed to get virtual hosts running, so for example: http://clienta.local works! And I could put http://clienta.local/index.php?page=home.... that works too.

Where in XAMPP should I look (file and folder would really help) to see where this AllowOverride should be, or where to add. If I can get htaccess running, I think I can possibly work thru tutorials to get tinyurl running.
Attachments
This is a screenshot to show the version i am using, in case that changes things too.
This is a screenshot to show the version i am using, in case that changes things too.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .htaccess file causing Server Error

Post by simonmlewis »

Code: Select all

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>
I just found this in httpd.conf.
Could this be the cause: Allowoverride *none* ???
Shouldn't that be set to All ??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: .htaccess file causing Server Error

Post by twinedev »

Dunno in XAMP, have no idea, I've only worked directly with servers, My guess on that screen shot would be the Setup button?
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .htaccess file causing Server Error

Post by simonmlewis »

This is what is shown on that setup button.
All leads said it is the AllowOverride to be "All", but that did not work, even after a restart.

It *MUST* be something in the config that disables htaccess from being used locally.
Attachments
&quot;Setup&quot; button
"Setup" button
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: .htaccess file causing Server Error

Post by twinedev »

simonmlewis wrote:

Code: Select all

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>
I just found this in httpd.conf.
Could this be the cause: Allowoverride *none* ???
Shouldn't that be set to All ??
No, that is the correct setting for the root of the system. There should be a similar block elsewhere that is for the root of your webdocs.

-Greg
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .htaccess file causing Server Error

Post by simonmlewis »

Code: Select all

<Directory "C:/xampp/htdocs">
    #
    # Possible values for the Options directive are "None", "All",
    # or any combination of:
    #   Indexes Includes FollowSymLinks SymLinksifOwnerMatch ExecCGI MultiViews
    #
    # Note that "MultiViews" must be named *explicitly* --- "Options All"
    # doesn't give it to you.
    #
    # The Options directive is both complicated and important.  Please see
    # http://httpd.apache.org/docs/2.2/mod/core.html#options
    # for more information.
    #
    Options Indexes FollowSymLinks Includes ExecCGI

    #
    # AllowOverride controls what directives may be placed in .htaccess files.
    # It can be "All", "None", or any combination of the keywords:
    #   Options FileInfo AuthConfig Limit
    #
    AllowOverride All

    #
    # Controls who can get stuff from this server.
    #
    Order allow,deny
    Allow from all

</Directory>
This?

Happy to upload my config file if it helps.
Just rebooted machine to see if that helped, but it didn't.

BTW it's an "Error 500" if that helps.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
User avatar
twinedev
Forum Regular
Posts: 984
Joined: Tue Sep 28, 2010 11:41 am
Location: Columbus, Ohio

Re: .htaccess file causing Server Error

Post by twinedev »

That looks ok, so not sure what will be causing it. I took your .htaccess file, put it on my server, and got no error. Sorry can't help you more.

-Greg
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .htaccess file causing Server Error

Post by simonmlewis »

Ok, I have found the answer!
In httpd-vhosts.conf, is where you have to setup the virtual host.
Even tho AllowOverride All is set in the config file, it also has to go in here.... where the virtual host is setup for each site.

So now I have that line, within the <directory> section and hey presto - WORKS!!

:)

onto the pain of working out tinyurls now.....
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
simonmlewis
DevNet Master
Posts: 4435
Joined: Wed Oct 08, 2008 3:39 pm
Location: United Kingdom
Contact:

Re: .htaccess file causing Server Error

Post by simonmlewis »

I have this on another thread, so apologies, but I now have virtual hosts and tinyurl sort of working, but where the url is:
http://clienta.local/page/selector
and the full url would be: index.php?page=selector
All files connected to it, either in images/ or source/, are all being looked for in
page/selector/images/

Why?? How do I get around this.

This is the thread I am trying this on:
viewtopic.php?f=1&t=133229
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
Post Reply