babelfish
05-29-2009, 10:20 AM
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:
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!
mic2100
05-29-2009, 11:17 AM
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
/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
babelfish
05-29-2009, 11:20 AM
i have:
LoadModule rewrite_module modules/mod_rewrite.so
in my httpd.conf in my apache2 folder. i dont have a http.conf file.
babelfish
05-29-2009, 11:31 AM
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
/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!
babelfish
05-30-2009, 11:46 AM
:( really need some help on this...
thanks in advance!
abduraooft
06-01-2009, 08:45 AM
i dont have a .htpasswrd file - what should be in it? sorry if im being dumb - never done much with apache before!
<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
babelfish
06-01-2009, 08:46 AM
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! :(
Coyote6
06-01-2009, 04:32 PM
im not even sure what the password is for to be honest!
The password stuff is for adding security to the administration pages.
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.
# 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.
babelfish
06-02-2009, 02:01 PM
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...
Coyote6
06-02-2009, 05:17 PM
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.
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.
babelfish
06-03-2009, 08:30 AM
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...
babelfish
06-04-2009, 08:40 AM
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! :)