Err... Whats's up Green? HTACCESS help anybody?
November 28, 2010 2:18 PM Subscribe
I am trying to replace all requests to a certain directory on my website with a certain image. Any request to http://mywebsite.com/specific_directory/*.* would be replaced with http://mywebsite.com/specific_img.jpg.
Ok, so I have my website:
http://mywebsite.com/
I want all requests for URLs in the following directory:
http://mywebsite.com/specific_directory/
to be replaced with http://mywebsite.com/specific_img.jpg
So if you tried loading
http://mywebsite.com/specific_directory/image.jpg
http://mywebsite.com/specific_directory/file_that_doesnt _exist.png
you would receive http://mywebsite.com/specific_img.jpg every time.
I would also like to preserve the requested file name if possible. They see http://mywebsite.com/specific_directory/image.jpg in their address bar but are served up http://mywebsite.com/specific_img.jpg.
Can anybody give me a hint on this? Is .htaccess the right way to go with this? I would like this to work for hotlinking and for anybody that tried accessing it from my website. I would also like this to work for files that do not exist in the directory. Is all this possible?
Ok, so I have my website:
http://mywebsite.com/
I want all requests for URLs in the following directory:
http://mywebsite.com/specific_directory/
to be replaced with http://mywebsite.com/specific_img.jpg
So if you tried loading
http://mywebsite.com/specific_directory/image.jpg
http://mywebsite.com/specific_directory/file_that_doesnt _exist.png
you would receive http://mywebsite.com/specific_img.jpg every time.
I would also like to preserve the requested file name if possible. They see http://mywebsite.com/specific_directory/image.jpg in their address bar but are served up http://mywebsite.com/specific_img.jpg.
Can anybody give me a hint on this? Is .htaccess the right way to go with this? I would like this to work for hotlinking and for anybody that tried accessing it from my website. I would also like this to work for files that do not exist in the directory. Is all this possible?
(Note: mod_rewrite assumes that you are using Apache, that no other parts of your site have monkeyed with things, etc. YMMV!)
posted by gregglind at 3:33 PM on November 28, 2010
posted by gregglind at 3:33 PM on November 28, 2010
Best answer: From memory
RewriteRule .*\.*$ http://mywebsite.com/specific_img.jpg [L]
in a .htaccess in the 'specific_directory' directory should do it
posted by handybitesize at 3:33 PM on November 28, 2010
RewriteRule .*\.*$ http://mywebsite.com/specific_img.jpg [L]
in a .htaccess in the 'specific_directory' directory should do it
posted by handybitesize at 3:33 PM on November 28, 2010
Yes, gregglind is correct that you need to be running Apache, but I rather assumed that was the case seeing as you mentioned .htaccess.
If you're not on Apache, then you should let us know what you're running.
posted by romakimmy at 4:40 PM on November 28, 2010
If you're not on Apache, then you should let us know what you're running.
posted by romakimmy at 4:40 PM on November 28, 2010
Response by poster: I am using Dreamhost and it looks like mod_rewrite is fully-supported on all DreamHost plans.
The following worked great:
Options +FollowSymLinks
RewriteEngine On
RewriteRule .*\.*$ http://mysite.com/specific_image.png [L]
It doesn't keep the typed URL, but it does what I need it to do for the most part. Thank you everybody.
posted by B(oYo)BIES at 6:16 AM on November 29, 2010
The following worked great:
Options +FollowSymLinks
RewriteEngine On
RewriteRule .*\.*$ http://mysite.com/specific_image.png [L]
It doesn't keep the typed URL, but it does what I need it to do for the most part. Thank you everybody.
posted by B(oYo)BIES at 6:16 AM on November 29, 2010
« Older Help me turn my apartment into a den of sin. | I need your best cookie recipe ever!!!! No... Newer »
This thread is closed to new comments.
posted by romakimmy at 3:32 PM on November 28, 2010