I should rewrite url
subdomain.test.com/login?xxxxxx
to
test.com/login?xxxxxx
how can I configure try files part for that?
.htaccess wont possible
Related
I have several url's that I would like to rewrite in NGINX
for example:
From: app.example.com/calendar
To: calendar.example.com
Or
From: app.example.com/meetings
To: meetings.example.com
I would still like to keep the app.example.com so it's not being removed from the redirect, but just create subdomains for certain URLs.
How can I do this in NGINX conf file?
All the best.
Redirect Subdomain to Folder in NGINX
Just add the following location block in your server configuration, inside server block, above the location / block.
location ^~ /calendar {
rewrite ^/calendar/?(.*)$ https://calendar.example.com/$1 permanent;
}
In the above code replace blog.example.com with your subdomain, and /calendar with your subdirectory. The above location block will listen to all requests sent to example.com/calendar. It redirects all those requests to calendar.example.com subdomain of your website. $1 is the URL stub after subfolder in requested URL. We add permanent keyword at the end of rewrite directive to cause a permanent redirect.
So it will permanently redirect subfolder to subdomain along with URL string.
I had a WordPress instance hosted on a subdirectory on a domain. I have now changed the domain and moved the WordPress setup to the root of a new domain.
I have set up .htaccess on the old domain root directory as follows.
Redirect 301 /subdirectory https://newdomain.com/
And it's working pretty well. But for some reason, the assets in the subdirectory chain are throwing 403 forbidden. The following pattern ends up with 403.
https://olddomain.com/subdirectory/wp-content/uploads/1.jpg
What I might be doing wrong here?
I have a dilemma. I migrated my wordpress site from Apapache server to NGINX.
In the process I changed permalink in WP from
/index.php/%postname%/
to
/%postname%/
Now, users coming to site from Google, are getting 404's because of the permalink change. Typically I would just redirect any page via WP plugin, but because of this index.php in the permalink, plugins don't work. So I have no choice but to create a redirection somewhere in NGINX conf file.
Please advise what to do.
server {
rewrite ^/index.php/(.*)$ /$1 permanent;
...
}
In the server configuration file (the file will be located at /etc/nginx/nginx.conf).
If it does not exist there, it may also be at /usr/local/nginx/conf/nginx.conf or /usr/local/etc/nginx/nginx.conf.
For temporary redirect:
rewrite ^/oldlocation$ http://www.newdomain.com/newlocation redirect;
For permanent redirect:
rewrite ^/oldlocation$ http://www.newdomain.com/newlocation permanent;
I am trying to understand regex URL rewrites and redirects.
I need the following:
www.mydomain.com/tag/*/index.html (for example, mydomain.com/tag/winter-holidays/index.html or mydomain.com/tag/summer-holidays/index.html) to redirect to: www.mydomain.com/index.php/tag/WHATEVER/index.html
www.mydomain.com/*/ (for example, www.mydomain.com/four-roots-of-happy-living/, www.mydomain.com/four-roots-of-happy-living (without the ending slash), www.mydomain.com/living/, www.mydomain.com/living (without the ending slash) AND ALSO www.mydomain.com/category/happiness/ and www.mydomain.com/category/happiness (without the ending slash) to redirect to www.mydomain.com/index.php/WHATEVER/ or www.mydomain.com/index.php/WHATEVER/ WHATEVER/.
I have tried so many different combinations in my .htaccess file that my head is spinning now.
In my .htaccess (currently) I had this, but have deactivated it for the meantime until I can get this straight:
Redirect 301 /* /index.php/*
RedirectMatch 301 /*(.*)/? /index.php/$1
Note: My htaccess file was/is in my root directory, my WordPress site is in a wp folder off that, and it did not have a .htaccess file.
I want to redirect an entire subdirectory on my site i.e. http://www.mydomain.com/subdirectory to the root domain of my site http://www.mydomain.com can someone please tell my how to do so via .htaccess?
I had tried with Cpanel and enabled wildcard redirect but, sadly it's not working!
The subdirectory is actually a separate WordPress installation.
Thanks
Look into this: 301 redirection
Put the following .htaccess file into the root directory:
Redirect /subdirectory http://www.example.com
(requires mod_alias to be loaded) or use mod_redirect and put the .htaccess file into the subdirectory:
RewriteEngine On
RewriteRule (.*) http://www.example.com/$1
See: http://httpd.apache.org/docs/current/rewrite/ for mod_rewrite documentation.