我如何获得的.htaccess从通配符子域名页面重定向到通配符子域文件夹 [英] How do I get .htaccess to redirect from wildcard subdomain page to wildcard subdomain folder

查看:276
本文介绍了我如何获得的.htaccess从通配符子域名页面重定向到通配符子域文件夹的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要重定向

http://*.domain.co.uk/services.php 

http://*.domain.co.uk/services 

其中, * 是通配符域。

在理想情况下,htaccess的应该阅读服务页面(因为我有一个以上的),并重定向到相同的服务文件夹。

Ideally, htaccess should read the services page (as I have more than one) and redirect to the same services folder.

这是因为我已经改变了我的PHP页面文件夹/的index.php

This is because I have changed my PHP pages to folder/index.php.

推荐答案

这添加到htaccess文件在你的文档根目录(S):

Add this to the htaccess file in your document root(s):

RedirectMatch 301 ^/([^/]+)\.php$ /$1/

您将最有可能需要一个斜线,因为如果它是你重定向到一个目录,mod_dir将重定向的再次为了增加结尾的斜线。

You'll most likely need that trailing slash because if it's redirecting you to a directory, mod_dir will redirect again in order to add the trailing slash.

编辑:

要排除,你必须使用mod_rewrite:

To exclude, you'll have to use mod_rewrite:

RewriteEngine On
RewriteCond %{REQUEST_URI} !index\.php
RewriteRule ^/?([^/]+)\.php$ /$1/ [L,R=301]

这篇关于我如何获得的.htaccess从通配符子域名页面重定向到通配符子域文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆