I've got a page www.mypage.com and I want to redirect specific URL to another URL that does not exist.
For example, I want www.mypage.com/about
to redirect to www.mypage.com/about-company.php
, where /about does not exists - it's a custom URL written by me.
I've got no dynamic URL, only want to tell through .htaccess
"this /CUSTOM_URL redirect to this /URL.php".
In the URL bar, it must show the custom url.
I don't know if it can be done. I've looked for it and all I've found are ways to rewrite dynamic URL and so, with patterns.
An example of that, would be the Permalinks of Wordpress, where you can specify which URL you want for each page.
You are looking for rewrite rules.
Some reading on that: Apache Rewrite rules
Try adding the following to the
.htaccess
file in the root directory of your site to get the specific example you requested to work: to accesswww.mypage.com/about-company.php
by usingwww.mypage.com/about
.If you wanted a more general rule e.g.
www.mypage.com/anything
is used to accesswww.mypage.com/anything.php
you could replace the rule above withOr you could have all requests to to a single .php file that decides what page to display e.g.
Building on Ulrich Palha's comment, I found that this worked for me as an .htaccess file to provide alternative redirects with masking to a couple of my own .php pages:
(I mention this because Ulrich's solution caused a problem for me when people typed example.com/about/ (with an ending slash)).
Thanks, Ulrich. If anyone knows how to modify Ulrich's .php-suffix Rule to descend recursively into any number of directories, I'd appreciate a comment!
As a temporary solution for anyone who needs to descend into directories, this worked for me:
The second command will handle the first subdirectory of all directories in the root folder of your website.
You can handle 3 levels of subdirectories, or 4, or 5, or 10, by just adding more instances of "/(\w+)" before the $ (one per new level of subdirectories), and then adding /$3, /$3/$4, /$3/$4/$5, or whatever is necessary immediately before ".php" in the Rule. I only needed 2 levels of directories (for now), so I'm good with what I posted; that solution is simple enough.
I'd still like a recursive solution if possible.