goose
goose

Reputation: 2642

htaccess redirecting URLs using rewrite rules

I'm working on a project within a sub-folder of my web-server. Since I've put the project has been moved all the javascript files are being sought in the wrong place. I want to solve this using htaccess but I don't know how and haven't been able to work it out.

How do I change URLs in the form:

/web/assets/9dd63ecf/css/jquery-ui-bootstrap.css

to:

/{subfolder}/web/assets/9dd63ecf/css/jquery-ui-bootstrap.css

Update Following Prix's advice I've tried the following rules:

Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
RewriteRule ^web/assets/(.*)$ /celebrant/web/assets/$1 [R=301,NC,L]

It's still not working however and I'm not sure why. Can anyone spot a mistake?

Upvotes: 0

Views: 215

Answers (1)

Prix
Prix

Reputation: 19528

This should work:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteRule ^web/assets/9dd63ecf/css/(.+)(\.css|js)$ /subfolder/web/assets/9dd63ecf/css/$1$2 [R=301,NC,L]

Or if you want anything on that folder you can resume it a bit:

Options +FollowSymLinks -MultiViews

RewriteEngine On
RewriteBase /

RewriteRule ^web/assets/9dd63ecf/css/(.*)$ /subfolder/web/assets/9dd63ecf/css/$1 [R=301,NC,L]

However if you have other rules on your .htaccess I may need to look at it to be sure they wont conflict.

The above rule assumes you want to change from:

http://domain.com/web/assets/9dd63ecf/css/jquery-ui-bootstrap.css 

To:

http://domain.com/subfolder/web/assets/9dd63ecf/css/jquery-ui-bootstrap.css 

Upvotes: 2

Related Questions