|
|
||||||
|
||||||
| Index Link To US Private Messages Archive FAQ RSS | ||||||
| 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. |
Share Thread: & Tags
|
||||
|
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|||
|
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 |
|
||||
|
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. |
|
|||
|
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. |
|
|||
|
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
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 |
|
||||
|
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. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| 301 in htaccess | inertia | Search Engine Optimization Forum | 7 | 01-07-2008 04:49 PM |
| .htaccess | apwade | Web Programming Discussion Forum | 2 | 10-12-2007 07:05 AM |
| .htaccess hell | dak888 | Web Programming Discussion Forum | 5 | 03-26-2007 05:30 PM |
| htaccess + redirect | newconceptdesign | Search Engine Optimization Forum | 5 | 02-14-2007 07:39 PM |
| how to make use of .htaccess | Miki | Search Engine Optimization Forum | 8 | 06-11-2005 10:53 AM |
|
WebProWorld |
Advertise |
Contact Us |
About |
Forum Rules |
MVP's |
Archive |
Newsletter Archive |
Top |
WebProNews
WebProWorld is an iEntry, Inc. ® site - © 2009 All Rights Reserved Privacy Policy and Legal iEntry, Inc. 2549 Richmond Rd. Lexington KY, 40509 |