Overwrite if the folder does not exist?

I have the following htaccess file:

RewriteEngine On RewriteRule ^([^/]*)$ /bio.php?bio=$1 [L] 

I need to do this:

  • Get the following rewritten URL: http://www.website.com/john-smith to go to /bio.php?bio=john-smith (such works at the moment)
  • If there is already a folder (for example, / about-us /), then show the file instead. At the moment this is happening, but does it add? Bio = about-us at the end.
  • Ideally, if possible, work with and without a trailing slash.

Any help is greatly appreciated.

thanks

+4
source share
1 answer

Try something like this:

 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ bio/bio.php?q=$1 [L] 

The first line will skip the RewriteRule if it finds the corresponding physical file; the second line will skip it if it finds the corresponding directory. The third line is the rewrite rule that will be executed if the previous conditions are met.

+12
source

Source: https://habr.com/ru/post/1332480/


All Articles