I need to setup about 5-6k redirects on a domain (for a site migration), and I'm new to nginx. I have some test redirects working in the main .conf file for the domain. But I don't want to have 5k+ rewrites in the main .conf file so I have been told that I can include a external file in the .conf to keep it clean, so my main .conf like this
server {
listen.....etc
etc
rewrite ^oldurl newurl permanent;
rewrite ^oldurl newurl permanent;
include /etc/nginx/conf.d/redirects.conf;
location ....etc
etc
}
Then in the redirects.conf I just have
rewrite ^oldurl newurl permanent;
But when I try to restart nginx I get the error:
"rewrite" directive is not allowed here in /etc/nginx/conf.d/redirects.conf:1
Thanks
OK, issue was I was calling the extenal file redirects.conf, since every file ending in .conf is considered a site configuration file.
I changed it to sitename.redirects and now it works fine
Related
I have my Teamcity instance been setup by defaults. Its behind nginx, so i had moved /WWW folder to /teamcity folder and had set nginx location record up like that.
location /teamcity {
proxy_pass http://localhost:8111/teamcity;
# and a couple of _sets here
}
everything works fine except Nuget feed. I can list packets from it but i cant download any packet because the packet URL.
It looks like:
1. http://some.domain.com:443/teamcity/whatever/url/for/the/packet/(correct one)
instead of:
2. https://some.domain.com/teamcity/(correct URL)
The packets at the second URL are accessible but feed returns me firs one. URLs in "General Settings" and "main-config.xml" are correct also. Is that because of URL auto detection, so can i disable it some how or is it because of another issue?
Server URL autodetect is not related to this problem. If you have custom URL specified, then autodetect will be disabled.
Make sure you pass all necessary headers as specified in our documentation: https://confluence.jetbrains.com/pages/viewpage.action?pageId=74845225#HowTo...-NGINX
Using omnibus gitlab 9.2.
Action: As a non-logged-in user, attempt a request for a public project that doesn't exist (at least not publicly).
Result: Receive a 302 redirect to /users/sign_in from nginx.
What I'd like to see: Receive a 302 redirect to /public (or wherever, for that matter)
What I've tried without success: Adding this to gitlab.rb:
nginx['custom_gitlab_server_config'] = "try_files $uri $uri/ /public;\n\nfastcgi_intercept_errors on;\n\n"
I couldn't find the explicit redirect in any nginx conf, so I guess it's in Rails. I'll peruse that code.
This is actually a custom HA configuration with the gitlab nodes behind haproxy fronts. I thought about possibly doing something on the fronts, but couldn't come up with anything.
Thanks!
Edit:
I see now that replacing the unmatched_route line in routes.rb with:
get '*unmatched_route', to: redirect('/public'), via: :all
does what I need, but I'd of course want to make that change persistent. Is that possible?
yesterday i switched my sites to a new server. now i have a problem, because one domain i now run as a subdomain, was previously accessed as a subfolder and a few sites, which I have no access to, are still using that domain.com/subfolder/?some=parameters
so, long story short:
i need to update my nginx config file, to redirect my users from domain.com/subfolder/?some=parameters to subfolder.domain.com/?some=parameters
i searched for a solution for that problem yesterday, but couldn't fix the problem.
currently i have this in my conf file:
location /subfolder/ {
rewrite ^/subfolder(/.*)$ http://subfolder.domain.com$1 permanent;
}
which obviously redirects all requests from domain.com/subfolder/?some=parameters to subfolder.domain.com/?some=parameters, but requests to domain.com/subfolder/styles.css aren't redirected.
I think this is due to a conflicting location directive for specific static file extensions in your nginx config. I was able to get your rule to work by making it use a regular expression which influences the priority.
location ~ /subfolder/.* {
rewrite ^/subfolder(/.*)$ http://subfolder.domain.com$1 permanent;
}
See the details about the location directive, especially the rules and examples there about precedence.
I'm trying to redirect traffic that attempts to access:
cat.rs.allgames.com/cloud/11/services/titles/game5/console/file.json
to:
cat.cloud.allgames.com/titles/game5/console/file.json
using a 301 permanent redirect in an .htaccess file, but it always sends me to:
cat.cloud.allgames.comcloud/titles/game5/console/cloud/11/services/titles/game5/console/file.json
which is nowhere near correct. What am I doing wrong?
My .htaccess is located in:
cat.rs.allgames.com/cloud/11/services/titles/game5/console/file.json
and looks like this:
Redirect 301 / http://cat.cloud.allgames.com
The Rewrite module should do what you want! You need to make sure the rewrite module is enabled (for ubuntu: sudo a2enmod rewrite), then add this to your .htaccess file.
RewriteEngine On
RewriteRule ^/cloud/11/services/titles/(.*)$ http://cat.cloud.allgames.com/titles/$1 [R=301]
Here, the ^/cloud/11/services/titles/(.*)$ catches anything after the titles part of the URL. Then the $1 at the end of the second part attaches what we caught to the end of the new URL. Finally, you can specify it as an external 301 rewrite to another server with the [R=301] flag!
Hope that works for you!
for some weird reason my CMS is logging out if the address bar does not have www before the full website name. for example, when we enter xyz.com, it takes me to the website but then it wont show as logged in and if i type in www.xyz.com it will find the cookie and show me logged in.
What i want to do is, when user types in xyz.com, i want it to directly (transparent to user) go to www.xyz.com. I want to add that www before xyz.com. I tried adding a .htaccess file in the directory where index.php is present and this is code in htaccess file.
DirectoryIndex index.php
Redirect xyz.com www.xyz.com/index.php
The .htaccess file is disappearing when i transfer it over ftp filezilla.
If you are willing to modify your index.php you could add the following logic to the top of the file:
/*This is a tempory redirection from mysite.com to www.mysite.com*/
if($_SERVER['SERVER_NAME'] == 'mysite.com')
{
$redirect = $_SERVER['REQUEST_URI'];
header( 'Location: http://www.mysite.com'. $redirect ) ;
}
try this in the htaccess file:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^xyz.com$
RewriteRule ^/?$ "http://www.xyz.com" [R=301,L]
However, your problem sounds like cookie related. Probably the CMS is using a cookie to check the log in status, but the cookie domain param is 'www.xyz.com' instead of '.xyz.com'.
--- edit ---
improved a bit the final line of the code (it is tested and working), but as tcp said, mod_rewrite must be enabled. If you can't enable it, try the code that Lobsterm posted and if you can't do this either, you could try to change the cookie domain param from 'www.xyz.com' to '.xyz.com'
If you want to use rewrites, make sure mod_rewrite is being loaded in your Apache conf file and check that the AllowOverride parameter is either set to All or the just the directives you want to be allowed in .htaccess
Also as aletzo said, you probably want your cookie to cover your whole domain so change the cookie domain from www.example.com to example.com .
Then, it won't matter if user are accessing with a www prefix or within a subdomain.
EDIT: Glad you found the answer you were looking for, but if you need to make filezilla show you .htaccess in the future, Server -> Force showing hidden files