Forum Moderators: phranque
I'm having a similar problem to [webmasterworld.com ]
I have a subfolder of a domain: example.com/NYC/ to which I want all server requests to be handled through NYC/index.php. I'm using:
RewriteEngine on
RewriteRule !\.(gif夸pg如ng圭ss存wf)$ /usr/home/example.com/htdocs/NYC/index.php [L]
It works like a charm but as you might see, my images are getting lost when I am linking to a URL like /NYC/restaurant/57/ The server is trying to access the images at /NYC/restaurant/57/images_home/image.gif.
I tried the solution presented in the link above however its not working. Maybe this is because I'm not on the domain root?
Please help. It is much appreciated. Thanks
[edited by: jdMorgan at 11:19 pm (utc) on Jan. 10, 2004]
[edit reason] No personal URLs, please -See TOS [/edit]
Welcome to WebmasterWorld [webmasterworld.com]!
Assuming your images are in /NYC/images, you could simply rewrite anything that makes it past your first rule to that images subdirectory. Alternately, your could specifically rewrite the images. The methods are equivalent because of the [L] flag on the first rule.
RewriteEngine on
RewriteRule !\.(gif夸pg如ng圭ss存wf)$ /usr/home/example.com/htdocs/NYC/index.php [L]
RewriteRule (.*) /NYC/images/$1 [L]
- or -
RewriteRule /?([^.]+\.(gif夸pg如ng圭ss存wf))$ /usr/home/example.com/htdocs/NYC/images/$1 [L]
Jim
This doesn't seem to work. Right now, I've got:
RewriteEngine on
RewriteCond %{REQUEST_URI}!^/NYC$
RewriteRule!\.(gif夸pg如ng圭ss存wf)$ /usr/home/example.com/htdocs/NYC/index.php [L]
This gets me all of my images when I access example.com/NYC with or without the trailing slash. The links on the index page are dynamically generated to go to say href="restaurant/52/" for example and then I have index.php using these parameters (restaurant and 52) to construct the page you see. The images are inside NYC/images.
When I use both of the examples above I am losing some of the images on the index page (strange) and I am still missing all of the images on the secondary pages which are accessing restaurant/52/images/image.gif
I have researched this problem for the last 12 hours and it seems every solution doesn't work for me. What am I missing?
BTW, I tried Rewritebase to htdocs like stated above and I get a file missing when I hit /NYC in my browser.
Tearing my hair out.
Ben
RewriteEngine on
RewriteRule!\.(gif夸pg如ng圭ss存wf)$ /usr/home/example.com/htdocs/NYC/index.php [L]
RewriteRule /?([^.]+\.(gif夸pg如ng圭ss存wf))$ /usr/home/example.com/htdocs/NYC/images/$1 [L]
and:
RewriteEngine on
RewriteRule!\.(gif夸pg如ng圭ss存wf)$ /usr/home/example.com/htdocs/NYC/index.php [L]
RewriteRule (.*) /NYC/images/$1 [L]
Both make a couple of the images on the index page not work (I have no idea why this happens). And the secondary pages are still accessing the wrong urls.
Well, some days ya get the bear, and some days the bear gets you... :(
You might be a lot happier if you change your relative links from src="something.gif" to src="/something.gif" or src="/NYC/images/something.gif". That leading slash declares the filepath to be relative to the root directory of the site, wherever that is. Basically, if all your pages are created by the script, then all relative links will be relative to the script location if you don't include the slash.
The above is the suggestion that's simplest for me... It may not be for you. But playing with it may give you a handle on a better solution, given your circumstances. By redirecting all "pages" to the script, you have essentially removed the structure of your site from the script directory on down, and the linking will have to be adjusted for the new "flat" site structure -- Or you will have to handle image requests on a case-by-case basis, which might lead to a *really* ugly .htaccess file.
Jim