we need to set rewrite rule for some images using .htaccess rules or nginx conf
Example 1
Request Path:
https://www.example.com//media/catalog/product/cache/1/thumbnail/543x403/db978388cfd007780066eaab38556cef/n/u/number1.png
Response Path:
https://www.example.com/pub/media/catalog/product/cache/543x403/n/u/number1.png
Example 2
Request Path :
https://www.example.com/media/catalog/product/cache/1/thumbnail/543x403/db978388cfd007780066eaab38556cef/l/e/legal_slide01.jpg
Response Path :
https://www.example.com/pub/media/catalog/product/cache/543x403/l/e/legal_slide01.jpg
Here the l/e/ directories are set according to the first two characters of image name here: legal_slide01.jpg
Thank you
Try:
rewrite ^/(media/catalog/product/cache)/\d+/thumbnail/(\d+x\d+)/[a-z0-9]+/(\S+) /pub/$1/$2/$3;
Regex check.
Related
I have my website inside the following path on my remote web hosting server:
~/public_html/website/app
and need to find a way to show it when typing:
mydomain.com
so without the need of typing the full path:
mydomain.com/website/app/
One solution that came to my mind was to create a index.php file inside my root folder to automatically redirect to ./website/app/:
<?php
header('Location: ./website/app/');
exit;
but then I need to rewrite the URL in order to go from:
mydomain.com/website/app/
to:
mydomain.com
and I did not find a way to do that!
So, what do you think I should do to obtain that result and show my website under /website/app/ when accessing:
mydomain.com
and do not show the /website/app/ folder names?
Thanks a lot!
edit:
I was forgetting that I also have the website/server path so I need a rule that keeps valid the requests containing mydomain.com/website/server/.
Plus, I cannot use:
Options +FollowSymLinks
on my hosting (for security reasons), it's overridden by:
Options +SymLinksIfOwnerMatch
You have two options to do that.
If you just want to show the /website/app directory for your root url / then you can use DirectoryIndex directive .
DirectoryIndex website/app
This will show you the index file from /website/app folder if you visit the your root URI ie : example.com/ .
If you want to server files and directories from the /website/app instead of the / folder then you can use a RewriteRule that rewrites your root level requests to the subfolders .
RewriteEngine on
RewriteRule !website/app /website/app℅{REQUEST_URI} [L]
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How to redirect non-www to www URL’s using htaccess?
My htaccess file is doing nothing although I am adding folloeing code in it.(I think it is not enable)
My current website address is like that www.abc.com/mvc/view/index.php
And the new address is www.abc.com/index.php
My hosting provider is godaddy.com. and there is also PHP.ini file in the same directory I have placed htaccess file in the root directory seems like html/.httaccess.The complete htaccess file is like
Redirect /mvc/view/index.php http://abc.com
But its not working.I am confused about .htacces file placement and also the rewrite code line. Can you please help me out?
The syntax for Redirect looks correct. Please note that you need to have a FileInfo permission:
Description: Sends an external redirect asking the client to fetch a different URL
Syntax: Redirect [status] URL-path URL
Context: server config, virtual host, directory, .htaccess
Override: FileInfo
You should ask your hosting provider whether you're allowed to use this directive.
I will present a to the point example.
I have a domain name as: www.abc.com
And another domain name as: www.123.com
Now i want to write a rewritemodule in .htaccess for the following case:
If i request a url like: www.123.com/xyz
It will redirect my request to www.abc.com/track/index.php?ext=xyz
Also please tell me on which directory i should keep that .htaccess file.
Thanks.
In the root folder of www.123.com, you would create an htaccess file with the following line:
RedirectMatch 301 (.*) www.abc.com/track/index.php?ext=$1
Since you are doing an external redirect, it is not necessary to use mod_rewrite.
I have to redirect a url to another url with all its parameters using htaccess.
My incoming url will be something like this:
www.mydomain.com/book-it.jsp?id=3&var1=values&var2=value2...
and I want to get it in PHP (book-it.php) as something like this (with all its parameters):
www.mydomain.com/book-it.php?id=3&var1=values&var2=value2...
I was using JSP and from now on moving to PHP and we need to use same URL since this url is already published with my application and I can't change that now. I need to get that url and parameters to another file.
You have 2 main approaches:
1) Using Redirect directive:
Redirect 301 /book-it.jsp http://www.mydomain.com/book-it.php
2) Using mod_rewrite module (this needs to be placed in .htaccess in website root folder. If placed in Apache config file (inside <VirtualHost>, for example) the rules need to be modified slightly):
RewriteEngine On
RewriteBase /
RewriteRule ^book-it\.jsp$ http://www.mydomain.com/book-it.php [QSA,NC,R=301,L]
Both of them will preserve query string.
I have a link from anther website that I do not have control of http://example.com/one two three.exe
The correct URL is http://example.com/one_two_three.exe
Note the underscores instead of spaces.
I searched the internet and found this code snippet for .htaccess
# Redirect old file path to new file path
Redirect /one%20two%20three.exe http://example.com/one_two_three.exe
I added this snippet to my preexisting root .htaccess at the top of the file.
But it does not seem to work. My browser does not redirect and I get a 404 error page.
I believe that it has something to do with the spaces in the original URL but I don't know how to handle spaces in the URL.
Suggestions?
You could try a couple of things (both untested)
Redirect "/one two three.exe" http://example.com/one_two_three.exe
or use RewriteRule instead of Redirect:
RewriteRule /one\ two\ three.exe http://example.com/one_two_three.exe