-1

I want to automatically redirect http requests to news/images to ../images.

Is that possible with .htaccess?

Thing is: request to www.site.tld/news/images ... should go to www.site.tld/images ...

I have tried:

RewriteEngine On
...
...
RewriteRule (.*)news/images(.*) ../images [R=301,L]

not working.

I have ensured that apache have mod_rewrite.c enabled.

greenV
  • 311
  • 3
  • 7
  • 2
    There are about 53974783027 answers to this alone here on StackOverflow. None of those helped you? _Why not_? And why should the 53974783028th suddenly help? What should be different with the one you ask here? Please read through a few of the "Related" entries shown on the right side. I am sure you will find your question answered there. – arkascha Jun 09 '16 at 15:23
  • What do you mean by not working? What error do you get? – anubhava Jun 09 '16 at 17:53

2 Answers2

0

You can use:

RewriteRule ^www\.site\.tld/news/images$ /www.site.tld/images?&%{QUERY_STRING}

or you can also use:

RewriteCond %{HTTP_HOST} ^www.site.tld/news/images$ [NC]
RewriteRule ^(.*)$ http://www.site.tld/images/$1 [R=301,L]

But as @arkascha said, please do some research first, there are MANY answers to this sort of problem! :) Either way, I hope this helps.

Joe
  • 4,877
  • 5
  • 30
  • 51
  • `HTTP_HOST` is the hostname only, without path info. And the `RewriteRule` pattern is only path info, without hostname. See [Apache Module mod_rewrite](http://httpd.apache.org/docs/current/mod/mod_rewrite.html) for details. – Olaf Dietsche Jun 10 '16 at 07:26
  • Thanks @OlafDietsche, I will take a look! :) – Joe Jun 10 '16 at 08:04
0

To redirect all requests for /news/images/ to /images/, capture the part after images and use it in the RewriteRule

RewriteRule ^news/images(.*)$ /images$1 [R,L]

When it works as it should, you may replace R with R=301. Never test with R=301.

Community
  • 1
  • 1
Olaf Dietsche
  • 72,253
  • 8
  • 102
  • 198