NGINX将所有子文件夹重定向到域根目录

时间:2018-02-28 16:02:47

标签: regex nginx

我需要将所有子文件夹重定向到根域,例如。 www.example.com/*到www.example.com。

我尝试了以下内容:

server {
    listen       80;
    server_name  www.example.com;

    location / {
        proxy_pass      http://site/;
        proxy_set_header Host            $host;
        proxy_set_header X-Forwarded-For $remote_addr;
    }

    location ~ ^/(.*?)/?$ {
        return 301 http://www.example.com;
    }
}

但它不起作用,我认为它会陷入重定向循环。

1 个答案:

答案 0 :(得分:0)

看起来你的正则表达式可能不正确。您可以使用regex101.com之类的网站来帮助您使用正则表达式。

Here是一个正则表达式的示例,它将在网址的apply plugin: 'com.android.application' android { compileSdkVersion 26 defaultConfig { applicationId "com.gorillachat.gorillachat" minSdkVersion 19 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { implementation fileTree(dir: 'libs', include: ['*.jar']) implementation 'com.android.support:appcompat-v7:26.1.0' implementation 'com.android.support:design:26.1.0' implementation 'com.android.support.constraint:constraint-layout:1.0.2' implementation 'com.google.firebase:firebase-auth:11.0.4' implementation 'com.android.support:support-v4:26.1.0' implementation 'com.google.firebase:firebase-database:11.0.4' implementation 'com.google.firebase:firebase-storage:11.0.4' implementation 'com.firebaseui:firebase-ui-database:2.3.0' implementation 'com.google.firebase:firebase-messaging:11.0.4' testImplementation 'junit:junit:4.12' androidTestImplementation 'com.android.support.test:runner:1.0.1' androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1' compile 'de.hdodenhof:circleimageview:2.2.0' compile 'com.theartofdev.edmodo:android-image-cropper:2.6.+' compile 'com.squareup.picasso:picasso:2.5.2' compile 'com.squareup.okhttp:okhttp:2.5.0' compile 'id.zelory:compressor:2.1.0' compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1' } apply plugin: 'com.google.gms.google-services' 部分之后的任何网址中注册为真实:

.com

相关问题