Forum Moderators: phranque

Message Too Old, No Replies

.htaccess rewrite

images won't load

         

StoutFiles

7:01 pm on Jun 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Cuurently I'm using the .htaccess file to change

www.mysite.com/stuff/stuff.php?items=5
to
www.mysite.com/stuff/5

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} (/stuff/)
RewriteRule ^stuff/([^/]+) /stuff.php?items=$1 [L]

However, when I do this none of the images on the page carry over. All the images are in the folder www.mysite.com/images/. I've tried just doing RewriteCond %{REQUEST_URI} (/images/) as well but that doesn't work...the whole process confuses me. Any help?

[edited by: StoutFiles at 7:05 pm (utc) on June 6, 2008]

g1smd

7:37 pm on Jun 6, 2008 (gmt 0)

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



URLs are defined by what is in the link on the page.

The browser resolves the URL for the image based on the URL of the page if the link to that image is relative.

Start the URL for the images with a leading slash to make it count from the root.

Make sure that your rewrite only rewrites for html files, or does not rewrite for a specific folder, like the /images/ folder.

StoutFiles

7:45 pm on Jun 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Start the URL for the images with a leading slash to make it count from the root.

Yeah, that did it. Feel kind of stupid now.

Marcia

7:48 pm on Jun 6, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My file naming and syntax is different (and the script sure probably is), but the pages are working with images all over - in the root /images/ folder, and the /foldername/images/ using this in .htaccess of the folder that it's in.

RewriteEngine on
RewriteRule ^(.*).html$ http://www.example.com/foldername/scriptname.php?file=$1 [QSA]

Shouldn't there be a $ at the end of the first half of your RewriteRule? And how about if you use the fully qualified URL in the second half?

-> Whoops, posted after the reply came.

Start the URL for the images with a leading slash to make it count from the root.

I've tried that, but never been able to get that to work.

>>Feel kind of stupid now.

I sure do, I have no idea how I got this thing working. If it breaks I'm a goner. :)

[edited by: Marcia at 7:55 pm (utc) on June 6, 2008]

jdMorgan

3:59 pm on Jun 8, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Marcia,

Be aware that by including the "fully-qualified URL" in your RewriteRule, you are forcing a 302 redirect to "scriptname.php" -- likely exposing "/scriptname.php" to the search engines, and likely defeating the original purpose of the rewrite. (Check for the 302 with a server headers checker).

For an internal rewrite, correct syntax would be:


RewriteEngine on
RewriteRule ^(.+)\.html$ /foldername/scriptname.php?file=$1 [QSA,L]

Unfortunately, without the external redirect, the relative-URL-resolution described by g1smd above occurs, and you'll likely have to apply the same fix as described.

Jim

g1smd

5:13 pm on Jun 8, 2008 (gmt 0)

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



The big clue in all of this is knowing what is a URL, and what is an internal filepath.