The example below is what I have tried with no luck. I would like to redirect all files in the folder /files/dump/ that start with 15EIP to /file-is-gone
rewrite ^/files/dump/15EIP(*.*)?$ /file-is-gone permanent;
Related
I wanna make some redirect but for this i need to parse domain to send other domain.
My old domain url like this
http://olddomain.com/bg/some-name-part-421.html
http://olddomain.com/bg/some-name-1231.html
http://olddomain.com/bg/some-name-product-name-221.html
I want to redirect this to like this
https://www.newdomain.com/magazin/some-name-part.html
https://www.newdomain.com/magazin/some-name.html
https://www.newdomain.com/magazin/some-name-product-name.html
I try to redirect them like this on server block
rewrite ^(/bg/)([a-z-]+-[0-9]+)\.html$ http://www.newdomain.com/magazin/$2 permanent;
Not working well making redirect like this
http://www.olddomain.com/bg/chervena-borovinka-bioherba-3694.html
https://www.newdomain.com/magazin/chervena-borovinka-bioherba-3694
I want to delete also as last part of number and - but i dont know why not working well
Thats my .htaccess:
RewriteEngine On
RewriteRule "^bg\/([^0-9]+(?<!-))-([0-9]+)(\.html)" "http://newdomain.com/magazin/$1$3" [R]
Dont forget to set the RewriteBase.
Heres the code: https://regex101.com/r/UdMqaQ/3/
Nginx
rewrite "^/bg\/([^0-9]+(?<!-))-([0-9]+)(\.html)" "newdomain.com/magazin/$1";
I'm trying to do a rewrite for nginx. It's working but for sub directories it is taking the root's index.php instead of the index.php in the individual subdir. This is how my directory structure looks like:
/index.php
/p/index.php
/c/index.php
and this is my rewrite:
if (!-e $request_filename){
rewrite ^/([^./]+)/?$ /index.php?act=$1 break; #need break?
rewrite ^/([^./]+)/(.+)/?$ /index.php?act=$1&upm=$2 break;
rewrite ^/([^./]+)/([^./]+)/?$ /$1/index.php?act=$2;
}
I tried adding an entry for each subdirectory but it doesn't work either:
location /p/ {
root /home/user/public_html/p/;
rewrite ^/([^./]+)/(.+)/?$ /index.php?act=$1&upm=$2 break;
}
Any ideas?
The rewrite ^/([^./]+)/([^./]+)/?$ /$1/index.php?act=$2; will never be executed as the previous rewrite will always match. You might try swapping rewrites #2 and #3.
The root /home/user/public_html/p/; is probably wrong as /p/ will appear twice as it is in the $document_root and the $uri.
The rewrite in your location /p/ should rewrite to /p/index.php and not /index.php?
#Starkeen solved this for an Apache configuration at Redirecting the content of a directory, but not the directory itself as well as some of its subdirectories and files, but we'll soon be moving to Nginx.
His very elegant solution for Apache:
RedirectMatch ^/category/((?!index|images|menu)[^/]+)/?$ /$1
Here, everything in the /category/ directory -- except for /category/index.php, the content of /category/images/ and the content of /category/menu/ -- is redirected to the root folder.
We tried the translation from htaccess to Nginx offered at http://winginx.com/en/htaccess,
location ~ ^/category/((?!index|images|menu)[^/]+)/?$ {
rewrite ^(.*)$ /$1 redirect;
}
but that didn't work.
For some reason, when we finally give up searching for a solution and end up asking for help, we often find one soon after. Here it is -- it works perfectly:
rewrite ^/category/((?!index|images|menu)[^/]+)/(.*)$ /$1 permanent;
A magento website transferred to Nginx and my 301 redirects are not working here.
Previous URL:
www.domain.com/store/food/two-year-supply-of-glide-r-chow-glide-a-mins.html
New URL:
www.domain.com//two-year-supply-of-glide-r-chow-glide-a-mins.html
Initially my .htaccess was
Redirect 301 /store/food/two-year-supply-of-glide-r-chow-glide-a-mins.html /two-year-supply-of-glide-r-chow-glide-a-mins.html
and now I have convert it to Nginx server format i.e.
location /store/food/two-year-supply-of-glide-r-chow-glide-a-mins.html {
rewrite ^(.*)$ /two-year-supply-of-glide-r-chow-glide-a-mins.html redirect;
}
Which is not working.
You conversion looks fine to me. sometime nginx server ignore .htacess file try with a new file named as nginx.conf and put your all htacess conversion in this.
Edit
# nginx configuration
location /store { rewrite ^/store/food/(.*)$ /$1 redirect; }
I think this might help you.
In my website, the main PHP script is named index.php. All URIs look similar to this:
index.php?section=FrontPage&l=ES_LA&view=multiple
In the htaccess file and using the mod_rewrite extension, I managed to remove the .php PHP extension, so the URI looks like this:
index?section=FrontPage&l=ES_LA&view=multiple
What I want to do now is to replace index.php with example in the path.
I've tried using:
RewriteRule ^example$ index.php
But when I try accessing example?section=FrontPage&l=ES_LA&view=multiple the server returns a 404 Not Found status code.
How can I fix this?