Forum Moderators: phranque
How can I rewrite the URLs for more files? By example, I want to move my image files (.jpg) from the root directory in a directory named "pics".
I know how do do this for the files one by one, by example:
RewriteRule ^MyPicture\.jpg$ pics/MyPicture.jpg [R]
but how can this be done for all the .jpg files from the root?
Something like
# RewriteRule ^(.*)\.jpg$ pics/? [R]
Thank you.
xt
Welcome to WebmasterWorld!
To *rewrite* only root-directory .jpg files to /pics subdirectory:
RewriteRule ^([^/.]+)\.jpg$ /pics/$1 [L]
RewriteRule ^([^/.]+)\.jpg$ http://www.example.com/pics/$1 [R=301,L]
Jim
The main aim is to ensure that those pages are indexed in google with the correct domain name.
Main domain is http://example.org
I created a subdirectory http://example.org/net/
Could someone please tell me how I can construct a RewriteRule to put in .htaccess such that
http://example.org/net/$1
Will appear on users browser like
http://example.net/$1
Where $1 is any file, in any subdirectory below
net/ that is referenced
Thanks for any help
Kavan
Welcome to WebmasterWorld!
You can't do what you're asking in the way that you are expecting. The process is backwards.
1) Change all links on all of your pages to point to the URLs you want to show in the browser.
2) Use mod_rewrite to detect those URLs when they are requested from your server, and 'point' them to the correct server directory where the content for those URLs is located.
Before doing all this, you must be sure that you have DNS set up for your .net domain, and that it points to the IP address of your server. You must also be sure that your host has configured the server in httpd.conf to recognize that secondary domain, and point requests to your directory.
If you use a control panel, then do not use mod_rewrite; Use the facilities provided by the control panel itself to do all of this.
If you do end up using mod_rewrite, then the code would be something like:
RewriteCond %{HTTP_HOST} ^(www\.)example\.net
RewriteRule (.*) /net/$1 [L]
Jim