0

I have a .php file that outputs html. In the html there are links in the form of anchor tags, eg:

<a href="https://www.example.com/page1.php">Page 1</a>

Can .htaccess be used to rewrite this as:

<a href="https://www.example.com/page1.html">Page 1</a>

...so in the .php file the code is written as the first example but when the page is inspected in the browser the served link is as the second example?

Thanks

  • No, it can not do that. mod_rewrite rewrites incoming _requests_, it has nothing whatsoever to do with what output your script generates. – CBroe Dec 07 '22 at 14:54
  • 1
    @CBroe `mod_substitute` *can*… I just would not really recommend it unless it's somehow your only option. – deceze Dec 07 '22 at 14:54
  • That’s what [_mod_rewrite_](https://httpd.apache.org/docs/current/mod/mod_rewrite.html) is for. You can use regular expressions to define how URLs are mapped to server side scripts. The usual pattern is to redirect everything to an index.php which does delegation based on $_SERVER['REQUEST_URI'] – Andy Dec 07 '22 at 14:56

0 Answers0