Forum Moderators: phranque

Message Too Old, No Replies

sef urls, error page and graphics folders

         

leeparts

6:45 pm on Jul 22, 2007 (gmt 0)

10+ Year Member



After some help from here, I have my htaccess file working properly and generating search engine friendly urls and adding a required backslash where needed. It has however caused two other issues.

(1) The graphics folder is not accessible now. The url would be www.example.info/graphics/image.jpg. It applies the url rules and I can not get images to display.

(2) How to handle the error.php file? If a url is www.example.info/test/ and someone types in www.example.info/tes/ it does not automatically forward to error.php unless the file ends in dot something ie .html or .php. Should I use a meta refresh?

Here is my htaccess file:

Options +FollowSymLinks
RewriteEngine On
RewriteBase /

ErrorDocument 404 /error.php

RewriteCond %{REQUEST_URI} ^[^\.]+[^/]$
RewriteRule ^(.*)$ http://www.example.info/$1/ [R=301,L]

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/([^/]+)/?$ /index.php?rootcatname=$1&catname=$2&lastcatname=$3&itemurl=$4 [L]
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /index.php?rootcatname=$1&catname=$2&lastcatname=$3 [L]
RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?rootcatname=$1&catname=$2 [L]
RewriteRule ^([^/.]+)/?$ /index.php?rootcatname=$1 [L]
RewriteCond %{HTTP_HOST} ^example\.info [NC]
RewriteRule (.*) http://www.example.info/$1 [R=301,L,NC]

Thank you for the past and future help

jdMorgan

7:07 pm on Jul 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



(1) The graphics folder is not accessible now. The url would be www.example.info/graphics/image.jpg. It applies the url rules and I can not get images to display.

Use a RewriteCond with a negative-match pattern to exclude paths you don't want rewritten.

RewriteCond %{REQUEST_URI} !^/graphics/

RewriteConds apply only to the single RewriteRule that follows.

(2) How to handle the error.php file? If a url is www.example.info/test/ and someone types in www.example.info/tes/ it does not automatically forward to error.php unless the file ends in dot something ie .html or .php. Should I use a meta refresh?

Never use meta-refresh. Ever. Unless you are forced by a criminal gang to host on GeoCities or something... :)

If you rewrite all requests to your script, then the script must decide if something "exists" or not. You will need to think about it it for several days, and decide exactly how the script can determine if something "exists" or not. If the script can't generate and serve something in response to a request, then the script should output a properly-formed 404 error response, and a message for the visitor to read that explains what happened.

PHP provides the "Header" function to output 403, 404, 410, and other error response headers:


header("HTTP/1.1 404 Not Found");
echo "full HTML code of 404 error document here";

Jim

[edited by: jdMorgan at 7:08 pm (utc) on July 22, 2007]

g1smd

7:16 pm on Jul 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



>> The graphics folder is not accessible now. The url would be www.example.info/graphics/image.jpg <<

I assume that the rewrite rules for pages could be put inside a <files "\.(htm?l¦php)$"> container so that only calls for "pages" would be rewritten.

Or did I miss something?

That would avoid having to add a negative match condition to each and every existing rewrite rule.

leeparts

8:24 pm on Jul 22, 2007 (gmt 0)

10+ Year Member



Determining if the file exists will be easy, as the code is pulling from a database. Thank you for you recommendation. I was concerned about duplicate content.

As far as the graphics folder issue goes. Do I need to place the negative match first, last? That does not seem to work.

g1smd

8:39 pm on Jul 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The RewriteCond needs to go in front of each and every one of the RewriteRule lines, one for each one.

leeparts

8:48 pm on Jul 22, 2007 (gmt 0)

10+ Year Member



Excellent. Works Perfectly.

Thank you both very much!

jdMorgan

10:18 pm on Jul 22, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> The RewriteCond needs to go in front of each and every one of the RewriteRule lines, one for each one.

Well no. It needs to go in front of any of the rules that might otherwise match the /graphics URL-path... I didn't finish that thought in my previous post... Pesky work interfering!

Or you could use a 'skip rule' to bypass all of those rules when the /graphics URL-path is requested...

Jim