如何在.htaccess中定义基本URL

时间:2017-02-18 00:45:38

标签: php .htaccess url-redirection subdirectory base-url

我正在重定向

AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

    // Prepare the Interstitial Ad
    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId("ca-app-pub-3940256099942544/1033173712");

    interstitial.loadAd(adRequest);

    interstitial.setAdListener(new AdListener() {
        public void onAdLoaded() {
            displayInterstitial();
        }
        public void onAdClosed() {
            requestNewInterstitial();
        }

    });
}

public void displayInterstitial() {
// If Ads are loaded, show Interstitial else show nothing.
    if (interstitial.isLoaded()) {
        interstitial.show();
    }
}

public void requestNewInterstitial() {
    mHandler.postDelayed(new Runnable() {
        @Override
        public void run() {
            AdRequest adRequest = new AdRequest.Builder()
                    .build();
            interstitial.loadAd(adRequest);

            if (mHandler != null) {
                mHandler.postDelayed(this, 100000); //time (ms)
            }
        }
    }, 100000); //time (ms)
}

https://www.example.com/inter.php?pid=<a number>&title=<the page title>

现在我想将网站移动到子文件夹,以便重定向

https://www.example.com/<a number>/<the-page-title>

https://www,example.com/folder/inter.php?pid=<a number>&title=<the page title>

我使用的是以下.htaccess代码

https://www.example.com/folder/<a number>/<the-page-title>

请建议。 谢谢!

1 个答案:

答案 0 :(得分:2)

如果您在根目录中使用.htaccess,则可以添加/ foldername

RewriteCond %{THE_REQUEST} /folder/inter\.php\?pid=([^&\s]+)&title=([^\s&]+) [NC]
RewriteRule ^ /foldername/%1/%2? [L,R]

同时遵守这两条规则

RewriteRule ^folder/([^/]+)/([^/]+)/?$ inter.php?pid=$1&title=$2 [L,QSA]

请尝试以上规则我暂时没有尝试过。