skip to Main Content

I have some simple URL like this

/sub/image.jpg
/sub/sub/sub/image.jpg

I want to redirect them to another page but when I use redirect code this page giving 404 error.

Redirect 301 /sub/1.jpg https://examplel.com/new-page

FYI: those images are not on my server now.

2

Answers


  1. You can use this generic redirect :

    RedirectMatch 404 ^/.*sub.+.jpg$
    
    Login or Signup to reply.
  2. You may also try this rule that matches any URI that starts with /sub/ and is not a file or directory:

    RewriteEngine On
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^sub/ https://examplel.com/new-page [L,NC,R=302]
    

    Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search