I want to redirect all images calls (.png,.jpg,.jpeg) from a specific folder, to another folder.
example.
www.somesite.com/dev/folder1/image1.jpg -> redirect to -> www.somesite.com/folder1/image1.jpg
Thanks
This should do it:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^(.*)\.(jpg|png|jpeg)$
RewriteRule ^dev/(.*)$ http://www.somesite.com/$1 [R=302,L]
Change the 302 to a 301 for a permanent redirect once you confirm it works (if the images will be moving permanently)
Related
I had a laravel project on a sub-domain and I migrated to another sub-domain.
I want to redirect all requests from old sub-domain to the new one.
For example:
https://old.website.com
https://old.website.com/login
https://old.website.com/contact
Should become:
https://new.website.com
https://new.website.com/login
https://new.website.com/contact
I moved all the files to another folder and added .htaccess with the following code:
RewriteEngine On
RewriteRule ^(.*)$ https://new.website.com/$1 [R=301,L]
But the issue is that public is added to the url for example:
https://old.website.com
Becomes:
https://new.website.com/public
So I get 404 not found error.
For the sub-domain I set the document root to point to public folder so no need to add the public directory to the url.
By the sounds of it, you likely have an internal rewrite to the /public subdirectory. Try the following instead:
RewriteRule ^ https://new.website.com%{REQUEST_URI} [R=301,L]
Test with 302 (temp) redirect first to avoid potential caching issues. You will need to clear your browser cache before testing.
I have this solution on one of my projects. To redirect requests from old sub-domain to the new one without the public folder in the URL, you could need to modify the .htaccess file. You can try the following code:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^old.website.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.old.website.com$
RewriteRule (.*)$ https://new.website.com/$1 [R=301,L]
This should redirect all requests to the new sub-domain while preserving the rest of the URL. This way, you should be able to access the pages at their new URL without encountering a 404 error.
I tried to redirect but not working even I put the correct code from take it from web.
Redirect /index.php?page=8 /?page=8
Redirect /index.php?page=8 /?page=8
The mod_alias Redirect directive does not match against the query string, so the above directive will never match, so does nothing.
To remove the index.php (directory index) from the visible URL, you would need to use mod_rewrite at the top of your .htaccess file. For example:
RewriteEngine On
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index\.php$ / [R=301,L]
The above will redirect a URL of the form /index.php?page=8 to /?page=8. Any query string present on the initial request is simply passed through to the target/substitution unaltered.
The condition that checks against the REDIRECT_STATUS env var ensures we don't get a redirect loop caused by mod_dir (or the Laravel front-controller) rewriting the request to index.php.
Clear your browser cache and test first with a 302 (temporary) redirect.
However, if you did only want to redirect the specific URL /index.php?page=8 (as stated in the question) to /?page=8 then you should write the rule like the following instead:
RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/index\.php?page=8\sHTTP
RewriteRule ^index\.php$ / [R=301,L]
Your htaccess code should be.
RewriteEngine On
RewriteRule ^index.php?page=$1 /?page=$1 [R=301,NC,L]
I am trying to configure how to redirect my magento website from www.domain.com/home to base url www.domain.com, it always redirecting to www.domain.com/home
UPDATE
Thanks Amit, I use your solution
RewriteEngine on
RewriteCond %{THE_REQUEST} ^.*/accueil
RewriteRule ^(.*)accueil$ http://www.cabas-durables.fr/$1 [R=301,L]
but I got error at the browser says
The page isn't redirecting properly
then I change the $1 after http://www.cabas-durables.fr/$1 to index.php, then it shows "http://www.cabas-durables.fr/index.php" at the browser, then I bring it back to $1 I got no error but it stays to "http://www.cabas-durables.fr/index.php"
I don't know where to change it to only "http://www.cabas-durables.fr/"
I will have problem with SEO if it not change
thanks
It can be better to use htaccess.
find
Options +FollowSymLinks
RewriteEngine on
Then
Put the below code in htaccess file
RewriteCond %{THE_REQUEST} ^.*/home
RewriteRule ^(.*)home$ http://www.domain.com/$1 [R=301,L]
Create URL Redirect in admin panel.
Use tagret path - "../"; it will redirect to the homepage.
I've just created a new website and am ready to switch from an my current webserver to a new webserver.
The current webserver will be renamed www2
The new webserver will be known as www
I want to redirect all traffic from www2 to www except for one directory. My directory structure looks like this:
/var
/www
/html
index.html
page2.html
/orange
index.html
...
/archive
index.html
important-page1.html
important-page2.html
/turquoise
index.html
...
I would like to redirect everything to the equivalent www page
e.g. www2.mydomain.com/orange/index.html -> www.mydomain.com/orange/index.html
www2.mydomain.com/turquoise/index.html -> www.mydomain.com/turquoise/index.html
EXCEPT for the /archive folder. I would like users requesting :
www2.mydomain.com/archive/important-page1.html to view the page on www2 and not be redirected.
Do I use mod_rewrite or mod_redirect? And can I set this up in httpd.conf?
Thanks
Yes, you would need mod_rewrite.
Try:
RewriteEngine on
RewriteCond $1 !^archive
RewriteRule (.*) http://www.mydomain.com/$1 [R=301,L]
Note: The 301 in R=301 is a permanent redirect, you'll need to change it to 302 if you want it to be temporary.
Within the VirtualHost config in httpd.conf (or httpd.conf.d file) for www2.mydomain.com add:
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/archive.*
RewriteRule ^(.*)$ http://www.mydomain.com$1
How can I go about redirecting my old URLs which would have been: http:// blah.com/some/post/name
to the new URLs which would be: http:// blah.com/new/some/post/name
Is this even possible?
I don't want to simply redirect any requests for the blah.com domain to blah.com/new
I want to make sure the subpath is still attached to the redirect
it should be possible.
Try to put this in your .htaccess file:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_URI} ^/some\/?
RewriteRule (.*) /new/$1 [R=301]
</IfModule>
Try it out and let me know - I haven't had time to test it very thoroughly.