1
votes

I have my drupal site at example.com and to configure in my local system i created a new folder drupal and pasted all the files inside this folder.

When i load my site at /localhost/drupal its loading but images are not loading as it is pointing to /localhost/sites/default/files/test.jpg in the content...i can't go and change in all the content...

Now to set .htaccess to take all the image path to /localhost/drupal/sites/default/files/test.jpg

<img alt="" src="/sites/default/files/finsoft-logo.png" style="width: 164px; height: 45px; ">

I tried like this but it is not wokring

RewriteRule ^/sites/default/files/(.*)$  /drupal/sites/default/files/$1 [L,NC]

Below is the code which i have in the .htaccess file

# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}

Please help me in solving this issue...

2

2 Answers

0
votes

Remove the leading slash from matching pattern:

RewriteRule ^sites/default/files/(.*)$ /drupal/sites/default/files/$1 [L,NC]
  • .htaccess is per directory directive and Apache strips the current directory path (thus leading slash) from RewriteRule URI pattern.
0
votes

You may need to set the $base_url in the settings.php file to get this fixed.

Something like $base_url = 'http://localhost/drupal';

Although, it might just be easier to fix your apache config file to set the root directory correctly.