H
H
HaruAtari2014-01-02 23:43:26
Apache HTTP Server
HaruAtari, 2014-01-02 23:43:26

RewriteRule not working?

Goodnight.
At the root of the site is .htaccess with the following content:

spoiler
AddDefaultCharset UTF-8
RewriteEngine on
#RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Options -Indexes

Previously, there was a storage directory with media files at the root of the site. Now it is placed on a separate subdomain. And you need to set up a 301 redirect from the old addresses to the new one. Those. the request of the form http://site.com/storage/images/1.pngshould redirect to storage.site.com/images/1.png
Regular I made:
RewriteRule ^storage/(.+)$ http://storage.site.com/$1 [R=301,L]
But you can't add it in a way that doesn't break something else.
If you enter it after RewriteRule . index.php, then it does not work. The request is passed to index.php (which is understandable).
If you enter before the existing rule, then the redirect starts working, but the additional ones stop connecting. files on the current domain (js, css, images).
Tell me how to change htaccess correctly so that the redirect works correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
H
HaruAtari, 2014-01-03
@HaruAtari

Poked, poked - figured it out.
It was necessary to add a condition for this rule, so that it would not always be fulfilled.

AddDefaultCharset UTF-8
RewriteEngine on
#RewriteBase /

RewriteCond %{REQUEST_URI} ^/storage/(.+)$
RewriteRule ^storage/(.+)$ http://storage.site.com/$1 [R=301,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Options -Indexes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question