 |

01-12-2008, 11:33 AM
|
|
WebProWorld New Member
|
|
Join Date: Dec 2007
Posts: 21
|
|
.htaccess Help!!
Hi, I have been having an issue with my .htaccess file. I am fairly new to webdesign but have managed to figured out most other scripting problems but I still have no clue how to configure my .htaccess file without getting errors. I am hoping someone here can help me out.
First let me show you my current .htaccess file:
Code:
#
# mod_rewrite in use
#
RewriteEngine On
# Uncomment following line if you get 403 Forbidden Error
Options +FollowSymLinks
# Uncomment following line if your webserver's URL
# is not directly related to physival file paths.
# Update YourMamboDirectory (just / for root)
#RewriteBase /YourMamboDirectory
#
# Rules
#
#RewriteCond %{REQUEST_URI} ^(/component/option,com) [NC,OR]
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^theticketlodge\.com
RewriteRule (.*) http://theticketlodge.com/$1 [R=301,L]
Really, all i want to do is have my Home - The Ticket Lodge - Discount Concert, Theater, and Sports Tickets redirect to Home - The Ticket Lodge - Discount Concert, Theater, and Sports Tickets. I tried to insert some code snippets I picked up to do this (as you will see from my mashing) but when I did I got an error: "No input file specified" and it redirects Home - The Ticket Lodge - Discount Concert, Theater, and Sports Tickets to http://theticketlodge.com/index.php/.
Ultimately, I do not want an index.php anywhere. I want that to point to just Home - The Ticket Lodge - Discount Concert, Theater, and Sports Tickets.
I also have a problem with 404 errors. I while back I had 404 errors sent to Home - The Ticket Lodge - Discount Concert, Theater, and Sports Tickets through my hosting account at GoDaddy. I believe this modified my .htaccess file. After I found out that a 404 error page is good for SEO I want to redirect it to my 404 error page.
If anyone can help me with these issues i would be very grateful. Please keep in mind that I have very little knowledge of the scripting in .htaccess files.
Thanks in advance!
gary
|

01-14-2008, 10:25 AM
|
 |
Moderator
|
|
Join Date: Jun 2006
Location: United States
Posts: 1,629
|
|
Re: .htaccess Help!!
Lets change a few things... first off, there is no need for the first three lines
#RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule ^(.*) index.php
The next line is not relevant (its a greedy operator that will always evaluate true, causing the next condition to skip)
#RewriteCond %{HTTP_HOST} .
That leaves us with the two lines that will actually do what you want, redirecting from www.whatever to just whatever
RewriteCond %{HTTP_HOST} !^theticketlodge\.com
RewriteRule (.*) http://theticketlodge.com/$1 [R=301,L]
Next, you just need to create the entry for your error documents. Supposing your error documents are in a folder called /errordocs/notfound.php:
ErrorDocument 404 /errordocs/notfound.php
ErrorDocument 403 /errordocs/notfound.php
Set the first line of your notfound.php script to be:
header("HTTP/1.0 404 Not Found", true, 404);
This will cause all errors to show up as "file not found" errors. If you restrict access to a folder for testing in the future for example, instead of the site serving a 403 forbidden message to unauthorized visitors, the user will see a file not found message.
|

01-15-2008, 09:43 AM
|
 |
Moderator
|
|
Join Date: Aug 2004
Location: Playing with fire!
Posts: 2,648
|
|
Re: .htaccess Help!!
wige...
Does this take care of the page defaulting to the /index.php folder as well?
Dave
|

01-15-2008, 09:56 AM
|
 |
Moderator
|
|
Join Date: Jun 2006
Location: United States
Posts: 1,629
|
|
Re: .htaccess Help!!
Not explicitly. It would eliminate the redirection to the index.php file (created by the three conditional statement) but not explicitly eliminate access to that URL. The full set of rules with a rule eliminating index.php, sending users to the / of all folders instead would be:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^theticketlodge\.com
RewriteRule (.*) http://theticketlodge.com/$1 [R=301,L]
RewriteRule ^(.*)/index\.php http://theticketlodge.com/$1/ [R=301, L]
|

01-15-2008, 12:48 PM
|
 |
Moderator
|
|
Join Date: Aug 2004
Location: Playing with fire!
Posts: 2,648
|
|
Re: .htaccess Help!!
Thanx wige!
Dave
|

01-15-2008, 11:27 PM
|
|
WebProWorld Member
|
|
Join Date: Apr 2004
Location: Melbourne, Australia
Posts: 36
|
|
Re: .htaccess Help!!
Hello Wige,
Just read your post which appeared to me so professional and kind.
As I have similar problem regarding being newbie with .htaccess I would like to have your kind assistance as well.
As I understand to rename domain name for search engines I would need to write and rewrite them in .htacess extension or I need allow or disallow in robots file. Some domains have already been rewritten in .htaccess files but it seems not all.
My old domain or site was Christian Science Healing Method Restores Physical Mental Health and my new one is Christian Science Healing Method Restores Physical Mental Health
After clicking old domain I get some either NOT FOUND or the following message:
"Warning: Unknown(): open_basedir restriction in effect. File(/home/healing/public_html/christian/index.htm) is not within the allowed path(s): (/home/blitch/:/usr/lib/php:/usr/local/lib/php:/tmp) in Unknown on line 0
Warning: Unknown(/home/healing/public_html/christian/index.htm): failed to open stream: Operation not permitted in Unknown on line 0
Warning: Unknown(): open_basedir restriction in effect. File(/home/healing/public_html/christian/index.htm) is not within the allowed path(s): (/home/blitch/:/usr/lib/php:/usr/local/lib/php:/tmp) in Unknown on line 0
Warning: Unknown(/home/healing/public_html/christian/index.htm): failed to open stream: Operation not permitted in Unknown on line 0
Warning: (null)(): Failed opening '/home/healing/public_html/christian/index.htm' for inclusion (include_path='.:/usr/lib/php:/usr/local/lib/php') in Unknown on line 0"
My .htaccess looks as follows:
# -FrontPage-
IndexIgnore .htaccess */.??* *~ *# */HEADER* */README* */_vti*
<Limit GET POST>
order deny,allow
deny from all
allow from all
</Limit>
<Limit PUT DELETE>
order deny,allow
deny from all
</Limit>
AuthName Christian Science Healing Method Restores Physical Mental Health
AuthUserFile /home/blitch/public_html/_vti_pvt/service.pwd
AuthGroupFile /home/blitch/public_html/_vti_pvt/service.grp
#Content type for diverse files
AddCharset UTF-8 .php
AddCharset UTF-8 .html
AddCharset UTF-8 .htm
AddCharset UTF-8 .css
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.html? [NC]
RewriteRule ^(([^/]*/)*)index\.html?$ http://www.christian-healing-prayer.net/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^christian-healing-prayer\.net [NC]
RewriteRule ^(.*)$ http://www.christian-healing-prayer.net/$1 [R=301,L]
As I've also changed the names of the articles files I would need to change them all on the Public server as well as they cannot be found.
Any way any tips regarding that matter would be greatly appreciated.
Thank you for your time and willingness to help.
So warmly, Michael.
|

01-16-2008, 08:38 AM
|
|
WebProWorld New Member
|
|
Join Date: Jan 2008
Posts: 2
|
|
Re: .htaccess Help!!
try to change your line
#RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
so should be more effective now
|

01-16-2008, 09:34 AM
|
|
WebProWorld New Member
|
|
Join Date: Dec 2007
Posts: 21
|
|
Re: .htaccess Help!!
Thanks for the Help Wige! It seems like there are few resources out there to help people with .htaccess issues so your reply will likely help a lot of people.
That said, your advice didn't exactly work as planned. Now I haven't yet tested what is required and what isn't, the
Code:
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php
appears to be required for some reason. I think part of it is required by the SEO extension i run in my CMS (Mambo).
Anyway I got the www to non-www to work but i still can't get the 404 error page to work. I use godaddy as my host and when i first started tinkering with the domain, i told them to point 404 errors to http://theticketlodge.com. When I tried to stop that (as I heard it is back for SEO), it just hasn't worked. Any clues?
Thanks again for all the help!
Gary
|

01-16-2008, 11:21 AM
|
 |
Moderator
|
|
Join Date: Jun 2006
Location: United States
Posts: 1,629
|
|
Re: .htaccess Help!!
Gary,
As far as the four lines, I think you may need to at the very least modify the first conditional so that .php files are handled.
RewriteCond %{REQUEST_FILENAME} !\.(jpg|jpeg|gif|png|css|js|pl|txt|php)$
Otherwise you have an endless loop. You are testing that the filename ends with a . and one of the listed extensions,, and if that fails you are redirecting the user to a page that has an extension not in the list - this causes an endless loop of redirects. The next two lines check if the requested file is a directory or a normal file, which basically means that the file has an associated MIME type. So the psuedocode for these for lines would be:
If the name of the requested file does not end in .jpg, .jpeg, .gif, .png, .css, .js, .pl, .txt or .php, and if it is not a directory that exists, and it is not a "regular file" (which includes html, htm and a few others) that exists, redirect the user to index.php.
One of the key things is that !-f, which checks if the requested document is a regular file, also tests if that file actually exists. This rule is applied before the ErrorDocument directive, so the user will be redirected to index.php, regardless of what you set to the ErrorDocument to.
On the basis that these four lines only handle security-like operations - preventing access to certain file types and testing if the files exist - and do not do any functional file name manipulations, removal of these lines should not have impacted your CMS, in any way I can think of. After removing the files, what broke, or what happened that shouldn't have?
By the way, I just saw an error in one of the lines I gave you. See my correction at the bottom.
Michael,
I tried to replicate the issue that you report, visiting http://www.christian.healing-prayer.net but I was redirected properly (I think) to http://www.christian-healing-prayer.net. I also tried it without the www subdomain, and was redirected to the same place. I did not get the error messages that you cite. Is there a specific URL that I should test to replicate the issue?
Looking at the error messages themselves, it looks more like a scripting error (bad root directory specification perhaps?) than an issue with the .htaccess file, but without replicating the problem I can't say for sure. In the .htaccess file itself, the only thing I might change is:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^/]*/)*index\.html? [NC]
RewriteRule ^(([^/]*/)*)index\.html?$ http://www.christian-healing-prayer.net/$1 [R=301,L]
I take it you are attempting to remove the filename from requests ending with index.html. Not a bad idea as it helps prevent a certain canonicalization issue. However, the lines to achieve it seem overly complex, and with anything that is complex, you have the chance of errors. For example, if you at some point create a folder that is ten characters long, the test will fail and the redirection won't happen ({3,9} would prevent it). Unless there is a specific issue that this requirement is intended to avoid, I would replace the two lines with:
RewriteRule ^(.*)/index\.html http://theticketlodge.com/$1/ [R=301, L]
Bleep. I just realized there is an error in this line. Sorry folks. See below for the corrected version.
Error Correction
I previously mentioned using RewriteRule ^(.*)/index\.php http://theticketlodge.com/$1/ [R=301, L] to remove the index.php from the end of a URL to prevent canonicalization errors. However, I just realized that this would not work on requests for the root index (http://www.yourdomain.com/index.php would resolve to http://www.yourdomain.com//). Sorry for the confusion. The correct way to handle this would be with two different rules, one which addresses the main root, and one which addresses all sub folders (regardless of depth in the site, could be sixteen directories deep, only need one rule). This is necessary because there are limited ways to handle the starting slash. You also need to have the flexibility to still include the word index in file names, so just testing for filenames ending with index.php or index.html would not be ideal. The following two lines will handle the issue properly, and it is script-safe, handling index.php and index.html.
RewriteRule ^/index\.(php|html)$ http://theticketlodge.com/ [R=301, L]
RewriteRule ^(.*)/index\.(php|html)$ http://theticketlodge.com/$1/ [R=301, L]
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|