Forum Moderators: phranque

Message Too Old, No Replies

Need help with htaccess directive

         

born2run

3:16 am on Dec 21, 2014 (gmt 0)

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



Hi my requirement is to redirect the following URL to another url:

http://www.example.com/*jpg to http://www.example.com.


Note that there is no dot before the chars jpg. Can anyone please set me up with the htaccess code for it? Thnaks a lot in advance!

not2easy

4:41 am on Dec 21, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Please take a minute or two to read the forum Charter: [webmasterworld.com...] it will help you see how things work.

You can find example codes here in the Library for rewrites: [webmasterworld.com...]

phranque

6:11 am on Dec 21, 2014 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



redirect the following URL to another url:

http://www.example.com/*jpg to http://www.example.com

shouldn't that be a 404?

lucy24

7:25 am on Dec 21, 2014 (gmt 0)

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



Note that there is no dot before the chars jpg.

And the significance of this is...? The asterisk isn't a wild-card character, if that's what you're getting at.

You're not trying to redirect all jpg requests to the root, are you? That makes no sense on any level. Unless, possibly, you've got a picture-hosting site that you're now shutting down.

born2run

8:15 am on Dec 21, 2014 (gmt 0)

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



I have many urls such as example.com/filenamejpg

There is no dot between the jpg and filename. This is a drupal site. It's driving me crazy as many urls are just similar file names. I need to 302 them and so google won't index them anymore. thanks

lucy24

7:39 pm on Dec 21, 2014 (gmt 0)

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



I need to 302 them

No. You don't. You need to 410 them. A 302 is the worst solution I can begin to imagine-- even worse than 301, which is bad enough.

That's assuming there is no actual "filename.jpg" corresponding to the spurious "filenamejpg". Otherwise you'd be doing a one-for-one redirect with added . dot.

The pattern is
[^.]jpg$

using either mod_rewrite (RewriteRule) or mod_alias (RedirectMatch) depending on what else you've got in your htaccess.