Denis Saidov
Denis Saidov

Reputation: 93

htaccess redirect to assets folder

Root: /assets /sms-sending

However, I have a ton of files: .svg, .png, .jpg only that are pointing to /sms-sending/assets, which is non-existence. How can I auto re-point those files to /assets instead of /sms-sending/assets

I already tried multiple answers, and wasn't able to find a similar problem.

Thanks

Upvotes: 0

Views: 648

Answers (1)

arkascha
arkascha

Reputation: 42885

Not sure why that situation should be special in any way. There are endless solutions for this here on SO. Except of course if your situation is different to what you actually wrote in the question ;-) We can't say, since you did not post any of all those attempts you already made yourself...

Probably this is what you are looking for:

RewriteEngine on
RewriteRule ^/?sms-sending/assets/(.*)$ /assets/$1 [END]

If you want to place that rule in side a dynamic configuration file (as opposed to the http servers host configuration), then you need to store that file in the http servers document root and you need to enable the interpretation of such files (see the AllowOverride) directive in the documentation). Also you obviously need to enable the rewriting module.

In case you receive an http status 500 with that (internal server error), then chances are that you operate a very old version of the apache http server. In that case try replacing the [END] flag with the [L] flag.

And a general hint: you should always prefer to place such rules inside the http servers (virtual) host configuration instead of using dynamic configuration files (.htaccess style files). Those files are notoriously error prone, hard to debug and they really slow down the server. They are only supported as a last option for situations where you do not have control over the host configuration (read: really cheap hosting service providers) or if you have an application that relies on writing its own rewrite rules (which is an obvious security nightmare).

Upvotes: 1

Related Questions