Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Unhappy help with .htaccess please....

    Hi peeps.

    im supposed to be taking over a website for my father in law soon.

    they website authors use a .htaccess file to rewrite some URLS to make them more user friendly.

    i cannot get this working in my test environment (easywamp framework)

    here are the contents from the .htaccess file:

    Code:
    RewriteEngine on
    #RewriteBase /obe3753/
    
    RewriteCond %{REQUEST_FILENAME} !index\.html
    RewriteCond %{REQUEST_FILENAME} !.*_data\.html
    RewriteRule ^(.+)\.html$ index.php?p=$1 [L,QSA]
    
    RewriteCond %{REQUEST_FILENAME} index\.html
    RewriteRule ^(.+)\.html$ index.php [L,QSA]
    
    <Files newbridge.php>
    AuthType Basic
    AuthName "Restricted Administration Page"
    AuthUserFile /var/www/vhosts/THEIR SERVER/httpdocs/.htpasswd
    require valid-user
    </Files>
    <Files pricelist.php>
    AuthType Basic
    AuthName "Restricted Administration Page"
    AuthUserFile /var/www/vhosts/WEBSITE URL/httpdocs/.htpasswd
    require valid-user
    </Files>
    i need to get this working in my test envirnment and then get it working on a host when i buy some space.

    any help appreciated - thanks guys!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #2
    Regular Coder mic2100's Avatar
    Join Date
    Feb 2006
    Location
    Scunthorpe
    Posts
    562
    Thanks
    15
    Thanked 28 Times in 27 Posts
    i suppose the first question is...

    have u enabled mod_rewrite in ur http.conf file? without this apache will not use them

    EDIT-------------------

    Also it looks like this is used to authenicate users

    Code:
    /var/www/vhosts/THEIR SERVER/httpdocs/.htpasswd
    i would say that this would need changing to the location on the windows server so that this file can be found.

    my mistake i ment httpd.conf file not http.conf
    Last edited by mic2100; 05-29-2009 at 11:30 AM.

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    i have:

    LoadModule rewrite_module modules/mod_rewrite.so

    in my httpd.conf in my apache2 folder. i dont have a http.conf file.
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mic2100 View Post
    i suppose the first question is...

    have u enabled mod_rewrite in ur http.conf file? without this apache will not use them

    EDIT-------------------

    Also it looks like this is used to authenicate users

    Code:
    /var/www/vhosts/THEIR SERVER/httpdocs/.htpasswd
    i would say that this would need changing to the location on the windows server so that this file can be found.
    i dont have a .htpasswrd file - what should be in it? sorry if im being dumb - never done much with apache before!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    anyone?
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #6
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    really need some help on this...

    thanks in advance!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    shameless bump!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,849
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    i dont have a .htpasswrd file - what should be in it? sorry if im being dumb - never done much with apache before!
    Code:
    <Files newbridge.php>
    AuthType Basic
    AuthName "Restricted Administration Page"
    AuthUserFile /var/www/vhosts/THEIR SERVER/httpdocs/.htpasswd
    require valid-user
    </Files>
    <Files pricelist.php>
    AuthType Basic
    AuthName "Restricted Administration Page"
    AuthUserFile /var/www/vhosts/WEBSITE URL/httpdocs/.htpasswd
    require valid-user
    </Files>
    Just comment all those lines by putting # before them, and don't upload this htacees file to your server, unless you really need it.

    To know more about htpasswd, see httpd.apache.org/docs/2.0/programs/htpasswd.html
    Last edited by abduraooft; 06-01-2009 at 08:49 AM.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #9
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    im not even sure what the password is for to be honest!

    im more confused by the mod rewrite stuff - as at the moment i cant get any of the links working in my test environment!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #10
    Regular Coder
    Join Date
    May 2009
    Location
    Moore, OK
    Posts
    282
    Thanks
    11
    Thanked 41 Times in 41 Posts

    Cool

    Quote Originally Posted by babelfish View Post
    im not even sure what the password is for to be honest!
    The password stuff is for adding security to the administration pages.

    Quote Originally Posted by abduraooft View Post
    Just comment all those lines by putting # before them, and don't upload this htacees file to your server, unless you really need it.
    Do not comment out these lines on the live server until you have implemented some other security features (ex through PHP user login). That would leave your admin pages unprotected on the live site. You will need to make sure you have a .htpasswd file. I would just google it. There are several sites out there that can help. Make sure the path to the file is correct. You may be able to get these .htpasswd files from the live server if you have the proper access.

    As for the scripts not running, I would comment out the .htpasswd part on your test server and make sure to add the server path of the site from the root folder to the RewriteBase and uncomment it. Ex if your site is one of several hosted from the same server then you may have several sites listed like this: localhost/site_1/ and localhost/site_2. Then the server path to add to the RewriteBase would be /site_1/. If there is only one website hosted in the server's root folder than just put a slash.

    Code:
    # Virtual path to the root folder on the server.
    RewriteEngine on
    RewriteBase /
    
    # If it is not the index.html page or a page that ends in _data.html then
    # rewrite the page to the index.php page and set its get statement for the p
    # (guessing page) variable to the name of the requested .html file without
    # the .html ending Ex - info.html will become index.php?p=info
    RewriteCond %{REQUEST_FILENAME} !index\.html
    RewriteCond %{REQUEST_FILENAME} !.*_data\.html
    RewriteRule ^(.+)\.html$ index.php?p=$1 [L,QSA]
    
    # If index.html is requested then rewrite it as index.php?  Not too sure
    # about that one because that should be done in one line of code I believe.
    RewriteCond %{REQUEST_FILENAME} index\.html
    RewriteRule ^(.+)\.html$ index.php [L,QSA]
    
    # Require a password to view the newbridge.php admin file.
    #<Files newbridge.php>
    #AuthType Basic
    #AuthName "Restricted Administration Page"
    #AuthUserFile /var/www/vhosts/THEIR SERVER/httpdocs/.htpasswd
    #require valid-user
    #</Files>
    # Require a password to view the pricelist.php admin file.
    #<Files pricelist.php>
    #AuthType Basic
    #AuthName "Restricted Administration Page"
    #AuthUserFile /var/www/vhosts/WEBSITE URL/httpdocs/.htpasswd
    #require valid-user
    #</Files>
    Also make sure to use a text editor that only uses plain text when working with .htaccess files. Ex notepad and not notepad2 I recently spent an entire month trying to figure out why my code was not working only to find out that Dreamweaver and TextEdit in plain text mode on my mac and Notepad2 on my pc were adding false returns to the end of the line causing all sorts of problems. Hope this helps and please take my interpretations of the code with a grain of salt. I am still pretty new at .htaccess files too.

  • #11
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    thanks for that mate. im still none the wiser on getting the mod rewrite to work though. any tips? i never understood the regexp syntax...
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #12
    Regular Coder
    Join Date
    May 2009
    Location
    Moore, OK
    Posts
    282
    Thanks
    11
    Thanked 41 Times in 41 Posts
    Code:
    RewriteEngine on
    RewriteBase /
    
    RewriteRule ^(.+)\.html$ index.php [L,QSA]
    Try just this part. It should rewrite any file ending in .html to index.php. I tested it on my server and it was working. I'm sure you have tried but I would go one line at a time through the code to try and find out which one is causing the problem.

    Quote Originally Posted by babelfish View Post
    i never understood the regexp syntax...
    As for the syntax basically the ^ means the beginning of the string being checked. If not on there then it can mean that other characters can be in front of the ones you are checking. String = test.html ^est\.html will return false while just est\.html should return true, because it will look for the matching syntax anywhere in the string and not just at the beginning.

    The () are used to set objects into a variable. I believe that is all they are used for but not for sure if they have other purposes. (.*)\.html index.php=$1 means place any of the characters found in the () into the variable $1.

    The . inside the regex means any character if it is not escaped with a \. then it literally means just a .

    The * means any number of the previous characters can be found.

    The + I think means 1 or more of the previous characters must be found.

    The $ sign means the end of the regular expression. Like the ^ just on the other end, so str = test.html the regular expression 'test' will return true while test$ will return false because test is not the last thing in the string.

    When used together ^ and $ will look at the string from beginning to end. ^test\.html$

    When writing the new path that the file is directing to there is no regular expression so you do not need to escape the .

    Hope this helps some.

  • Users who have thanked Coyote6 for this post:

    babelfish (06-03-2009)

  • #13
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Coyote6 View Post
    Code:
    RewriteEngine on
    RewriteBase /
    
    RewriteRule ^(.+)\.html$ index.php [L,QSA]
    Try just this part. It should rewrite any file ending in .html to index.php. I tested it on my server and it was working. I'm sure you have tried but I would go one line at a time through the code to try and find out which one is causing the problem.



    As for the syntax basically the ^ means the beginning of the string being checked. If not on there then it can mean that other characters can be in front of the ones you are checking. String = test.html ^est\.html will return false while just est\.html should return true, because it will look for the matching syntax anywhere in the string and not just at the beginning.

    The () are used to set objects into a variable. I believe that is all they are used for but not for sure if they have other purposes. (.*)\.html index.php=$1 means place any of the characters found in the () into the variable $1.

    The . inside the regex means any character if it is not escaped with a \. then it literally means just a .

    The * means any number of the previous characters can be found.

    The + I think means 1 or more of the previous characters must be found.

    The $ sign means the end of the regular expression. Like the ^ just on the other end, so str = test.html the regular expression 'test' will return true while test$ will return false because test is not the last thing in the string.

    When used together ^ and $ will look at the string from beginning to end. ^test\.html$

    When writing the new path that the file is directing to there is no regular expression so you do not need to escape the .

    Hope this helps some.
    cheers mate! you are a star! i will look into this tomorrow...
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson

  • #14
    Regular Coder
    Join Date
    Jun 2002
    Location
    England =)
    Posts
    523
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Coyote6 View Post
    Ex if your site is one of several hosted from the same server then you may have several sites listed like this: localhost/site_1/ and localhost/site_2. Then the server path to add to the RewriteBase would be /site_1/. If there is only one website hosted in the server's root folder than just put a slash.
    doh! yeah all my sites are in folders on the server - looks like the regbase was the issue! lmao!

    thanks for the help mate - really got me out of a sticky situation!
    "They hired me for my motivational skills. Everyone at work says they have to work much harder when I`m around" Homer J Simpson


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •