maddig

Rewrite auf einen Unterordner mit NGINX

Guten Morgen,

ich habe ein kleines Problem.

Und zwar will ich wenn ich www.domain.de aufrufe, ein Rewrite einrichten dass dann sofort www.domain.de/cms daraus macht.
Grund ist, dass ich den root-Pfad nicht verschieben will, weil in ihm noch Ordner sind die ich brauche.

Als Webserver dient NGINX.


rewrite ^(.*) http://domain.de/cms$1 permanent;

Das habe ich schon probiert, nur dann schreibt er beim aufrufen ca. 30 mal /cms dahinter und der Brwoser gibt aus das ich zu oft von der Website weitergeleitet wurde..

Ich hoffe ihr könnt mir helfen.

MFG
Auf Facebook teilen
Auf X (Twitter) teilen
Auf Reddit teilen
Auf Linkedin teilen

Content-ID: 314575

Url: https://administrator.de/forum/rewrite-auf-einen-unterordner-mit-nginx-314575.html

Ausgedruckt am: 07.07.2025 um 06:07 Uhr

Lochkartenstanzer
Lochkartenstanzer 07.09.2016 um 08:09:45 Uhr
Moin,

Du hast eine klassische rekursionsschleife gebaut. Bevor Du den rewrite machst, mußt Du natürlich prüfen, ob Du überhaupt umleiten mußt.

lks
129813
129813 07.09.2016 aktualisiert um 08:14:59 Uhr
You are rewriting all paths, including the redirected one, which results in a loop.
rewrite ^/?$ http://www.domain.de/cms permanent
Regards
maddig
maddig 07.09.2016 um 08:22:27 Uhr
Thanks highload,

wenn i try your solution and restart nginx i get this error:

Reloading nginx configuration (via systemctl): nginx.serviceJob for nginx.service failed. See 'systemctl status nginx.service' and 'journalctl -xn' for details.
129813
Lösung 129813 07.09.2016 um 08:24:43 Uhr
Or this
if ($request_uri !~ "^/cms"){  
  rewrite ^(.*)$ http://www.domain.de/cms$1 permanent
}
maddig
maddig 07.09.2016 um 08:45:21 Uhr
perfect now it works ! thank you
Lochkartenstanzer
Lochkartenstanzer 07.09.2016 aktualisiert um 09:16:51 Uhr
Moin,

You schouldn't give always the direct solution, rather give hints. At least, the TOs should have a chance to learn by reading manuals. face-smile

BTW: Do you prefer replies in german for learnig german or in english for easy reading?

lks
129813
129813 07.09.2016 aktualisiert um 09:42:56 Uhr
Zitat von @Lochkartenstanzer:
You schouldn't give always the direct solution, rather give hints.
Is this "The Millionaire Quiz Board" face-big-smile
At least, the TOs should have a chance to learn by reading manuals. face-smile
Thats's true but we cannot force him to. It will fall him on his foot, early enough face-wink

BTW: Do you prefer replies in german for learnig german or in english for easy reading?
The first face-smile With reading i get a feeling and a visual experience for the words. Will try to write some answers in german in the near future if i feel myself confident.
Lochkartenstanzer
Lochkartenstanzer 07.09.2016 um 09:56:56 Uhr
Zitat von @129813:

Zitat von @Lochkartenstanzer:
You schouldn't give always the direct solution, rather give hints.
Is this "The Millionaire Quiz Board" face-big-smile
At least, the TOs should have a chance to learn by reading manuals. face-smile
Thats's true but we cannot force him to. It will fall him on his foot, early enough face-wink

Naja, Wenn die Leute alles auf denm Präsentierteller bekommen, erzieht man sie dazu, daß sie die Lösungen nur aus Internet-Foren ergooglen und erfragen, statt einfach mal auf die manpage zu schauen. Da hätte sich das if-statement geradezu aufgedrängt. Und wenn jemand keine manpages lesen kann, wird er sehr oft blaue Zehen bekommen.

BTW: Do you prefer replies in german for learnig german or in english for easy reading?
The first face-smile With reading i get a feeling and a visual experience for the words. Will try to write some answers in german in the near future if i feel myself confident.

o.k. Werde also in ZUkunft deutsch antworten. Aber trau Dich ruhig. Wir helfen auch gerne bei Sprachproblemen. N'es pas? face-smile


lks
129813
129813 07.09.2016 um 10:45:43 Uhr
erzieht man sie dazu, daß sie die Lösungen nur aus Internet-Foren ergooglen und erfragen
Well, i restrict myself to raise my kids face-wink.
Und wenn jemand keine manpages lesen kann, wird er sehr oft blaue Zehen bekommen.
In the next job interview, i will ask the candidate to take off his shoes face-wink then everything's clear.