.htaccess 301 redirect of single page
RedirectMatch
uses a regular expression that is matched against the URL path. And your regular expression /contact.php
just means any URL path that contains /contact.php
but not just any URL path that is exactly /contact.php
. So use the anchors for the start and end of the string (^
and $)
:
RedirectMatch 301 ^/contact\.php$ /contact-us.php
301 redirect any page to one specific page
Yes, that is possible -- instead of mod_rewrite you need to use mod_alias (which has more chances to be enabled).
This one will redirect everything to index.html
on newsite.com/
RedirectMatch 301 ^/(.*)$ http://newsite.com/index.html
This one will redirect everything to the same path but on another domain: (e.g. oldsite.com/meow.php
=> newsite.com/meow.php
)
RedirectMatch 301 ^/(.*)$ http://newsite.com/$1
.htaccess 301 redirect all pages on old domain to a single page on new domain
You can use RedirectMatch in the old.com vhost
RedirectMatch permanent .* http://www.new.com/
Redirect
appends the trailing portion of the matched URI to the redirection URI but with RedirectMatch
it's up to you to choose the parts (if any) that you want to transfer using parentheses and $number
references.
If the old and new domains must be aliases for the same document root on disk then you'll probably have to use mod_rewrite
RewriteEngine on
RewriteCond %{HTTP_HOST} old\.com$
RewriteRule .* http://www.new.com/ [L,R=301]
Htaccess 301 redirect is only redirecting domain not also the page
Posting my answer in comment section here so that readers can find it easily later
You need to use this rule instead for precise matching:
RedirectMatch 301 ^/page-old/ https://www.domain2.com/page-new/
Redirect
is non-regex directive that works with starts-with match.
Related Topics
Simple PHP SQL Login Troubleshooting
How to Explode and Trim Whitespace
How to Create a Custom Admin Page in Opencart
Understanding MVC: Whats the Concept of "Fat" on Models, "Skinny" on Controllers
Should My PHP Functions Accept an Array of Arguments or Should I Explicitly Request Arguments
In PHP, How to Extract Multiple E-Mail Addresses from a Block of Text and Put Them into an Array
Detect MySQL Update/Insertion Failure Due to Violated Unique Constraint
Executing PHP Code Inside a .Js File
PHP Regex Delimiter, What's the Point
Autoload Classes from Different Folders
PHP Cli: How to Read a Single Character of Input from the Tty (Without Waiting for the Enter Key)