How do I get .htaccess to redirect from wildcard subdomain page to wildcard subdomain folder

荒凉一梦 提交于 2020-01-05 05:47:08

问题


I want to redirect

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

to

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

where * is a wildcard domain.

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

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


回答1:


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

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

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.


EDIT:

To exclude, you'll have to use mod_rewrite:

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


来源:https://stackoverflow.com/questions/18539141/how-do-i-get-htaccess-to-redirect-from-wildcard-subdomain-page-to-wildcard-subd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!