[ask] cara redirect subdir di nginx


cLeo

Poster 2.0
saya ada web yang menggunakan format url berdasarkan direcroty
misalnya:

Code:
example.com/sub1/sub2/sub3
example.com/sub1/sub2/sub3/

dan saya ingin me-redirect semua url jika url melebihi 3 subdir, misalnya:


Code:
example.com/sub1/sub2/sub3/sub4 redirect to homepage.

example.com/sub1/sub2/sub3/sub4/sub5 redirect to homepage.

example.com/sub1/sub2/sub3/sub4/sub5/ redirect to homepage.

dan seterusnya



saya coba pake kode berikut di nginx tapi gak semua teredirect bahkan subdir ke 3 masih diredirect.

Code:
rewrite ^/([^/]+)/([^/]+)/([^/]+)/([^/]+) / permanent;

mohon bantuannya. terima kasih :)
 

UpCloud

Beginner 1.0
Halo! Sori, bhs indo saya ga bagus. Saya sarankan rewrite kayak gini:

server {
...
rewrite ^/$ /folder1/folder2;
...
}

Oiya, juga tau bahwa URL-URL yg berkaitan akan dikaitkan dengan to /not /folder1/folder2. Rewrite nya juga akan perform redirek secara internal tanpa pengguna/pengunjung web om ketahuan jadi domain URL akan ditetapkan sbg yourdomain.com apabila merka di website nya. Ini saranan saja ya :)
(Do keep in mind any relative URLs will be relative to / not /folder1/folder2
A rewrite will also perform the redirection internally without informing the user, so your domain URL will stay as yourdomain.com while serving. Depending on your use case, this may or may not be ideal.) - Safwah, perwakilan UpCloud :)
 

mlutfiup

Hosting Guru
server {
...
rewrite ^/$ /folderone/foldertwo;
...
}


By default, rewrite performs the redirection internally without informing the user about it. As a result of that, the URL will stay as http://yourdomain.com/ while actually serving http://yourdomain.com/folderone/foldertwo. Keep in mind that any relative URLs will be relative to /, not /folderone/foldertwo.
 

    
Top