问题
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