Let's say I have links like this:
http://www.example.com/media/images/my_file123.jpg
I want to rewrite this to:
http://www.example.com/my_images/my_file123.jpg
Means: Rewrite /media/images/ to /my_images/.
How can I do this with .htaccess?
You can use the following Rule
RewriteEngine on
RewriteRule ^my_images/(.+)$ /media/images/$1 [L,NC]
This rewrites /my_images/image.ext to /media/images/image.ext .
From the documentation, it seems like you can just write
Redirect /media/images/ /my_images/
Assuming that this is all relative to the root of your web folder.
Related
I want to rewrite from a subdirectory to a subdirectory.
Example, I have an application on http://example.com/level1/level2.
Now I want to be able to visit http://example.com/level1 and the application should be opened which is on http://example.com/level1/level2.
Im just trying to figure out the rewrite rule since 2 hours, but nothing seems to work.
Is this even possible, or is rewriting only possible from root directory?
Thanks
put this code in your /level1/.htaccess file:
RewriteEngine On
RewriteBase /level1/
RewriteRule ^((?!level2/).*)$ level2/$1 [L,NC]
this is what I currently have:
http://www.example.com/main?page=2
http://www.example.com/query?page=5
http://www.example.com/archives?page=2
And I want to replace it with:
http://www.example.com/main/2
http://www.example.com/query/5
http://www.example.com/archives/2
But I still want to have $_GET['page'] :)
How to do it with htaccess?
In the htaccess file in your document root, add these rules (preferably above any routing rules that you may have):
RewriteEngine On
RewriteRule ^(.*)/([0-9]+)$ /$1?page=$2 [L]
I have a website set up where I store all my user profiles in /member-centre/member-directory/USERNAME
My problem is that a number of referrals are posting to a depreciated structure of /members/USERNAME
Is there a way I can configure my .htaccess file to automatically post the requested USERNAME to the correct location? All i've found on google is static redirection.
If this is not possible through .htaccess, is there another method I could use?
Many thanks in advance
If you are looking for a redirect solution, Jon Lin's will work fine. If you want to do a rewrite then put the following in your .htaccess file in the root of your domain
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/members/([^/]+)$ [NC]
RewriteRule . member-centre/member-directory/%1 [L]
if member/centre etc is relative to the root filesystem and not your domain then replace the last line with (just leading slash)
RewriteRule . /member-centre/member-directory/%1 [L]
Do you mean something like:
RedirectMatch 301 ^/members/([^/]+)/? /member-centre/member-directory/$1
This redirects the browser with a permanent redirect.
Try something like this:
RewriteRule ^members/ /member-centre/member-directory/ [L]
I have just moved from Drupal + Wordpress to a site completely built in WordPress.
Duly I have a set of images where the files no longer exist and need to try and keep all the images in the one folder (if possible). Duly I need to send requests for any gif|png|jpg that are for http://www.domain.com/blog/wp-content/uploads/ to http://www.domain.com/wp-content/uploads.
If anyone could help would be appreciated - my .htaccess aint what it once was. Thanks in advance
If you google for "htaccess redirect", the top link is this:
http://www.htaccessredirect.net/
If you use the "301 Redirect Directory" section, you get this code:
//301 Redirect Entire Directory
RedirectMatch 301 /blog/wp-content/uploads/(.*) /wp-content/uploads/$1
As far as I know the target domain should be absolute, so the following might work:
//301 Redirect Entire Directory
RedirectMatch 301 /blog/wp-content/uploads/(.*) http://www.domain.com/wp-content/uploads/$1
Please try this rule in your .htaccess:
RewriteEngine On
RewriteRule ^/blog/wp-content/uploads/(.+)\.(png|gif|jpg)$ wp-content/uploads/$1.$2 [QSA,L]
Try this
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://www.domain.com/blog/wp-content/uploads [NC]
RewriteRule .* http://www.domain.com/wp-content/uploads [NC,L]
You could try and put this
RewriteEngine ON
RewriteRule ^/blog/wp-content/(.*)$ http://newdomain.com/wp-content/$1 [R=301,L]
What I have hated about all the re-write rules and redirect options for .htaccess files is they all rely on hardcoding the path (URI) and/or server for the redirect.
The point of the ".htaccess" files it it should be for the current directory! It could be referenced in a number of different ways, installed on different servers in different locations. So trying it down to a specific location for a simple directory rename is illogical.
The solution is to somehow incorporate the current URI (regardless or where the ".htaccess" location) into the result...
This is my current solution for location independent ".htaccess" redirect for a renamed sub-directory, and even I admit it is not perfect... BUT IT WORKS...
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^OLDdir/.*$ %{REQUEST_URI}::: [C]
RewriteRule ^(.*)/OLDdir/(.*)::: $1/NEWdir/$2 [R,L]
I have a page '/communities/communities.html' which i want to redirect to './communities.aspx"
my httpd.ini file looks like this but I cant get it to work. It just acts like there is no redirect.
redirect 301 /communities/communities.html http://www.thecondopros.com/communities.aspx
Try this instead in your site root:
RewriteEngine on
RewriteBase /
RewriteRule communities/communities.html http://www.thecondopros.com/communities.aspx [R=302]
Also ISAPI_Rewrite3 defaults to naming the naming the rewrite rule file .htaccess and not httpd.ini.
or, the correct answer:
RewriteRule communities/communities.html http\://www.thecondopros.com/communities.aspx [I,R=301]
you probably want I to make it case insensitive, and you want R=301
have some docs: http://www.isapirewrite.com/docs/