I’m trying what I thought would be something really simple of masking my url but cannot seem to get it to work. I want to be able to link to images in my img tag without having to type in the full url.
i.e.
Current url: http://server.com/wp-content/themes/standard/images/img.jpg
or
<img src = "http://server.com/wp-content/themes/standard/images/img.jpg" />
However on my pages I want to just do
<img src="http://server.com/images/img.jpg" />
However nothing seems to be working on my localhost. I am running the Apache server on a windows 7 machine. I am trying to use a .htaccess to do what I’ve mentioned above. Here is my .htaccess file in the root of my website.
UPDATE:
I tried ZweiBlumen suggestion below but that did not seem to work. I then tried Geerts suggestion and added the re-write method to my misc.php of my admin folder. I then went to my permalinks page and hit save. The result of doing this meant my .htaccess folder was rewritten and the output it produced is below.
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteRule ^css/(.*) /wp-content/themes/standard/css/$1 [QSA,L]
RewriteRule ^js/(.*) /wp-content/themes/standard/js/$1 [QSA,L]
RewriteRule ^images/(.*) /wp-content/themes/standard/images/$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
However, I still cannot navigate to my images folder such as:
http://localhost/images/myimage.jpg.
All I get is a page not found. Joshua’s suggestion worked perfectly however I’m hoping to use this in conjunction with masking the images URL.
Is there anything else I might be doing wrong, or should check?
UPDATE:
For anyone reading this, I just tried again and it has worked using a combination of Geerts and Joshuas methods. My Firefox browser appears to have been caching the page which was causing me to think it wasn’t.
The reason I went with this over putting it in the .htaccess file is that this file is overwritten every time I go to the permalinks Admin page and so I don’t won’t to overwrite this by accident. I guess I could turn this off somehow but not sure how to do that. All three answers helped to some degree.
Check out the Roots WordPress Theme. They seem to do exactly what you want with the URLs.
Here’s a snippet from their roots-htaccess.php file:
Note: if you can pull this off directly in a
.htaccess
file, as in ZweiBlumen’s answer, you should pick that solution since it most probably is more optimized.If the issue is only with images, but not css or javascript, I think there’s a typo in your RewriteRule. I think your missing a “1” after the “$”:
Also, you might want to try putting those extra statements below the initial rule, ie below this line:
Not sure though.
Why don’t you create a shortcode for that in the following manner.
And then use the following shortcode anywhere in the content area.