WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > IT Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox Mark Forums Read

IT Discussion Forum Having IT issues? Got IT questions? Who doesn't? If you can't get your Apache to work with your MySQL or your php is choking on your ODBC... Let's see if we can help you come up with some ideas.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 01-12-2008, 11:33 AM
garyglow garyglow is offline
WebProWorld New Member
 

Join Date: Dec 2007
Posts: 21
garyglow RepRank 0
Default .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
Reply With Quote
  #2 (permalink)  
Old 01-14-2008, 10:25 AM
wige's Avatar
wige wige is offline
Moderator
WebProWorld Moderator
 

Join Date: Jun 2006
Location: United States
Posts: 1,629
wige RepRank 4wige RepRank 4wige RepRank 4
Default 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.
__________________
The best way to learn anything, is to question everything.
Interestingly Average Security Blog
Reply With Quote
  #3 (permalink)  
Old 01-15-2008, 09:43 AM
crankydave's Avatar
crankydave crankydave is offline
Moderator
WebProWorld Moderator
 

Join Date: Aug 2004
Location: Playing with fire!
Posts: 2,648
crankydave RepRank 3crankydave RepRank 3crankydave RepRank 3
Default Re: .htaccess Help!!

wige...

Does this take care of the page defaulting to the /index.php folder as well?

Dave
Reply With Quote
  #4 (permalink)  
Old 01-15-2008, 09:56 AM
wige's Avatar
wige wige is offline
Moderator
WebProWorld Moderator
 

Join Date: Jun 2006
Location: United States
Posts: 1,629
wige RepRank 4wige RepRank 4wige RepRank 4
Default 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]
__________________
The best way to learn anything, is to question everything.
Interestingly Average Security Blog
Reply With Quote
  #5 (permalink)  
Old 01-15-2008, 12:48 PM
crankydave's Avatar
crankydave crankydave is offline
Moderator
WebProWorld Moderator
 

Join Date: Aug 2004
Location: Playing with fire!
Posts: 2,648
crankydave RepRank 3crankydave RepRank 3crankydave RepRank 3
Default Re: .htaccess Help!!

Thanx wige!

Dave
Reply With Quote
  #6 (permalink)  
Old 01-15-2008, 11:27 PM
mib mib is offline
WebProWorld Member
 

Join Date: Apr 2004
Location: Melbourne, Australia
Posts: 36
mib RepRank 0
Default 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.
Reply With Quote
  #7 (permalink)  
Old 01-16-2008, 08:38 AM
ajouter32 ajouter32 is offline
WebProWorld New Member
 

Join Date: Jan 2008
Posts: 2
ajouter32 RepRank 0
Default 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
__________________
http://www.ajouter32.com - humour jardin
Reply With Quote
  #8 (permalink)  
Old 01-16-2008, 09:34 AM
garyglow garyglow is offline
WebProWorld New Member
 

Join Date: Dec 2007
Posts: 21
garyglow RepRank 0
Default 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
Reply With Quote
  #9 (permalink)  
Old 01-16-2008, 11:21 AM
wige's Avatar
wige wige is offline
Moderator
WebProWorld Moderator
 

Join Date: Jun 2006
Location: United States
Posts: 1,629
wige RepRank 4wige RepRank 4wige RepRank 4
Default 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]
__________________
The best way to learn anything, is to question everything.
Interestingly Average Security Blog
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > IT Discussion Forum
Tags: htaccess, redirects



Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
301 in htaccess inertia Search Engine Optimization Forum 7 01-07-2008 03:49 PM
.htaccess apwade Web Programming Discussion Forum 2 10-12-2007 06:05 AM
.htaccess hell dak888 Web Programming Discussion Forum 5 03-26-2007 04:30 PM
htaccess + redirect newconceptdesign Search Engine Optimization Forum 5 02-14-2007 06:39 PM
how to make use of .htaccess Miki Search Engine Optimization Forum 8 06-11-2005 09:53 AM


Search Engine Friendly URLs by vBSEO 3.0.0