Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

.htaccess file to index.php file doesn't work

Posted on 2009-07-06
21
1,549 Views
Last Modified: 2013-12-13
I am trying to configure lilrul a open source url shortening device onto a ubuntu 8.10 intrepid lamp stack.

I have successfully installed the database using a combination of heidi, and phpmyadmin
However on the original install I did not use the .htaccess file to get the url to point to the index.php, and I am encountering strange errors.  When I input a long url, and have it shortened I receive no errors however the link is broken.

Trying the install on a fresh server image as of now I'm looking to try and use a .htaccess file to direct the webserver as per the instructions however, I have no idea if the .htaccess file is working or where to place it.

Not sure where to look at this point.
/etc/lilurl
 
lilURL 0.1.1 http://lilurl.sourceforge.net
 
lilURL is a simple PHP/MySQL app that works basically like tinyurl.com,
allowing you to create shortcuts on your own server.
 
-----------------------------------------------------------------------
 
To install:
 
1. Create a MySQL database and user for lilURL.
 
2. Import the lilurl.sql file:
 
      (( like so:
 
         mysql -u <lilurl_user> -p <lilurl_db> < lilurl.sql
 
      ))
 
3. Edit the configuration file includes/conf.php to suit your needs.
 
4. Set up mod_rewrite, if necessary
 
      (( a .htaccess file with the lines:
 
         RewriteEngine On
         RewriteRule (.*) index.php
 
        should suffice ))
 
5. Buy 15 donuts and eat them all in one sitting.
 
Those are the setup instructions for lilurl
 
Below is my /etc/lilurl/includes/conf.php file
 
<?php /* conf.php ( config file ) */
 
// page title
define('PAGE_TITLE', 'lil&#180; URL Generator');
 
// MySQL connection info
define('MYSQL_USER', 'dabney');
define('MYSQL_PASS', 'coleman');
define('MYSQL_DB', 'lilurl');
define('MYSQL_HOST', 'localhost');
 
// MySQL tables
define('URL_TABLE', 'lil_urls');
 
// use mod_rewrite?
define('REWRITE', true);
 
// allow urls that begin with these strings
$allowed_protocols = array('http:', 'https:', 'mailto:');
 
// uncomment the line below to skip the protocol check
// $allowed_procotols = array();
 
?>

Open in new window

0
Comment
Question by:Illyankesh
  • 12
  • 9
21 Comments
 
LVL 57

Expert Comment

by:giltjr
ID: 24790449
The .htaccess file needs to go in to the sites root directory, normally pointed to by DocumentRoot.

In the Directory settings for the site you also need to allow overrides.
0
 

Author Comment

by:Illyankesh
ID: 24790577
so that would be /var/www?  since it is just the simple 'it works!' default html script at the moment.  

As for The allowing overrides that should be set to on.  That would be in the apache.conf?
that is the snippet from the apache.conf  should the Deny from all say Allow?  The wording is confusing and makes it sound like I still want that denied?
 
AccessFileName .htaccess
 
#
# The following lines prevent .htaccess and .htpasswd files from being
# viewed by Web clients.
#
<Files ~ "^\.ht">
    Order allow,deny
    Deny from all
</Files>

Open in new window

0
 
LVL 57

Expert Comment

by:giltjr
ID: 24790630
If your DocumentRoot is /var/www, then that is where the .htaccess file shouldgo.

No,  the "Deny from all" should stay that way.

What the does is exactly what the comment says, it prevent me from entering:

     http://your.web.url/.htaccess

or

     http://your.web.url/.htpasswd

and pulling up your .htaccess file or your .htpasswd file.
0
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

Author Comment

by:Illyankesh
ID: 24790696
So still not working, even with the .htaccess file in the /var/www directory.
The link below fixes the webpage of the lilurl, but I suspect is behind the other problems.
Suggestions?


ln -s /etc/lilurl/index.php /var/www/index.php
0
 
LVL 57

Expert Comment

by:giltjr
ID: 24790740
In the:

<Directory />

</Directory>

Do you have:

     AllowOverride All

or any other AllowOverride?
0
 

Author Comment

by:Illyankesh
ID: 24790910
Don't think so what file would that be in?  I just have a standard LAMP stack on ubuntu, I'm not using any funky gui's to manage this.
Would that be /var/www ?
or is that the /etc/apache2/apache.conf?

0
 
LVL 57

Expert Comment

by:giltjr
ID: 24790985
I have not use Ubuntu, but I think it should be in apache.conf
0
 

Author Comment

by:Illyankesh
ID: 24791048
Ooooo that is progress now ...after adding AllowOverride All into the apache.conf file I get the below error.
So perhaps my .htaccess file is not written correctly?


Failed to Connect
 
      
 
      
      
      
 
      
        
        
 
          
 
Firefox can't establish a connection to the server at 174.129.94.248.
 
        
 
 
        
        
 
Though the site seems valid, the browser was unable to establish a connection.
 
    * Could the site be temporarily unavailable? Try again later.
    * Are you unable to browse other sites?  Check the computer's network connection.
    * Is your computer or network protected by a firewall or proxy? Incorrect settings can interfere with Web browsing.
 
 
RewriteEngine On
RewriteRule (.*) /index.php
 
 
should the /index.php  have the full path to the file I'm assuming?
 
        
        
      
 
 
      
      

Open in new window

0
 

Author Comment

by:Illyankesh
ID: 24791053
Nope nevermind that was my bad I got a

 * Restarting web server apache2                                                                                 Syntax error on line 38 of /etc/apache2/apache2.conf:
AllowOverride not allowed here


when adding the AllowOverride bit to the file
0
 

Author Comment

by:Illyankesh
ID: 24791065
Progress,
Uncommented a large string of stuff at the end of the apache.conf file including one that that said AllowOverride None, and changed that to AllowOverride All

Now I get this error.

The requested URL was not found on this server.  The link on the ">referring page seems to be wrong or outdated. Please inform the author of ">that page  about the error.  If you entered the URL manually please check your spelling and try again.

0
 

Author Comment

by:Illyankesh
ID: 24791168
which is weird since apache is running, and when I chop off the /index.php  I get the default it works page
...any ideas?
0
 
LVL 57

Expert Comment

by:giltjr
ID: 24791308
Rename the .htaccess file and see if the site works.
0
 

Author Comment

by:Illyankesh
ID: 24795968
Rename it to what?  .htaccess I'm assuming?
0
 
LVL 57

Expert Comment

by:giltjr
ID: 24796051
Anything.  The idea is NOT to use it and see if the basics of Apache is working.

Once you verify the basics are working, then rename it back to .htaccess.

If everything is working, when you enter:

      http://your.web.url

the .htaccess file will redirect you to:

     http://your.web.url/index.php

If you enter:

     http://your.web.url/somepage.html

it will re-direct you to:

     http://your.web.url/index.php

also.
0
 

Author Comment

by:Illyankesh
ID: 24796129
ok, set apache.conf back to default, and renamed .htaccess file.

I get
Not Found

The requested URL /index.php was not found on this server.
Apache/2.2.9 (Ubuntu) PHP/5.2.6-2ubuntu4.2 with Suhosin-Patch Server at 174.129.94.248 Port 80

when attempting to go to http://myurl/index.php

When I go to http://myurl
I get the default
It Works!  apache standard welcom page

0
 

Author Comment

by:Illyankesh
ID: 24796765
There was an extra Directory section in the sites-available/default file.  I made a couple of other minor changes, but it was a very difficult problem to diagnose, because it just kept looking like we had the wrong regular expression in the mod_rewrite line.  So, I kept trying pretty much every permutation of the the regex I could think of with no impact.  Deleting the extra Directory section cleared up the whole problem, and the regex that came with the lilurl distro worked like a charm.

This cleared up the overall problem on the main server... still have no idea why the .htaccess was not working.
0
 
LVL 57

Expert Comment

by:giltjr
ID: 24797308
If you entered:

    http://myurl/index.php

and got a 404 not found, that means that in your DocumentRoot (/var/www) you did not have the file "index.php".  Please note, if you are not familiar with Linux, file names are case sensitive, so index.php is not the same as INDEX.PHP, or even Index.PHP.
0
 

Author Comment

by:Illyankesh
ID: 24797354
Right.  The index.php file is in /etc/lilurl  which is why I needed the .htaccess redirect to get people there.
I had the .htaccess in the /var/www/ and was still not working.  though I did get some of the weirder errors last night, when I began playing with some of the /etc/apache2/apache.conf files.  Which are listed above.

Renaming the .htaccess file brought me the 404 error again...which was what I was getting last night after I only commented out some of the error files at the bottom of the apache.conf file.

0
 
LVL 57

Accepted Solution

by:
giltjr earned 500 total points
ID: 24797752
All files referenced by a URL must be in a directory that is defined in Apache by a <Directory></Directory> stanza.

If you had the .htaccess to just redirect http://myurl to http://myurl/index.php, the better way to do that is to get rid of the .htaccess and then in your apache.conf file change:

     DirectoryIndex index.html

To

     DirectoryIndex index.php

This will make the default page index.php.
0
 

Author Closing Comment

by:Illyankesh
ID: 31600413
Thanks man, was a combination of my newbness, and some strange errors which took my chief engineer the greater part of last night to figure out.
The softlink solution worked over the .htaccess file.  I was trying to get the .htaccess file solution to work in an effort to troubleshoot the greater error that was involved.  Which was infact an entire extra directory was being created by the index.php file.  Once that directory was removed, the rest of the script functioned as normal.
So the Softlink solution would infact also work as well as changing the default root directory.
0
 
LVL 57

Expert Comment

by:giltjr
ID: 24800099
Glad I could be of help.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Wordpress Pagination Function Not working ? 7 39
Google Maps API and PHP 25 49
Wordpress French and English Site 6 77
IP 10.0.1.2 / 255.0.0.0 61 56
It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question