jacksparrow007
jacksparrow007

Reputation: 1328

htaccess redirection using regular expression

my .htaccess file contains the following

RewriteCond %{HTTP_HOST} ^www\.mydomain\.org\.in [NC]
RewriteRule ^(.*)$ http://mydomain.org.in/$1 [R=301,L]

I moved the whole site to a subfolder and now none of the css and js files in the webpage load. Can anybody tell me what this regex means or why this is happening?

Note: I inherited the site from my seniors :P

Upvotes: 1

Views: 534

Answers (2)

somnath
somnath

Reputation: 1335

As Will explained the .htaccess is not the issue. Your JS and CSS locations were mentioned not relatively and as such when the location of the source files changed they are not being found by the browsers and as such the page is not rendering.

However, you can try the following .htaccess code in addition to the one you are having and see if it links to the files.

RewriteRule ^(.+)\.css$ http://mydomain.org.in/folder/$1.css [R=302,NC]
RewriteRule ^(.+)\.js$ http://mydomain.org.in/folder/$1.js [R=302,NC]

The above code redirects calls to css and js files to a subfolder in your domain. Change folder to the folder you moved everything to.

Upvotes: 0

Will Vousden
Will Vousden

Reputation: 33348

It just redirects any request to www.mydomain.org.in/... to mydomain.org.in/...; i.e. it strips the www from the front. However, this shouldn't cause the resource files to break if you simply move it to a subdirectory, assuming you've moved them as well (though you should probably leave the .htaccess file where it is).

It sounds like the links to your CSS/JS files in your HTML might be broken, perhaps because they use absolute URIs (relative to the domain root rather than the current URI). Try checking them first.

Upvotes: 1

Related Questions