在.htaccess中使用重写mod

I'd like to write a rewrite rule to do the following: if any of the following files exist on the server as a static html file in a specific directory then I'd like .htaccess to serve that static file. Otherwise, I'd like the id (first number after the .com/ and before the first hyphen) to be passed as a query parameter to www.gallery.com/index.php

Redirect should occur for the following URLs if it doesn't exist as a static HTML page.

 www.gallery.com/2-swimming.html
 www.gallery.com/2
 gallery.com/2

Below is my entire .htaccess file

<Files .htaccess> 
   order allow,deny 
   deny from all 
</Files> 


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENANE} !-f
RewriteCond %{REQUEST_FILENANE} !-d
RewriteRule ^([0-9]+)-(.*)\.html$ /index.php?id=$1 [L]
</IfModule>

Is there anything wrong with my rewrite condition.(I'm having a hard time). Also what is an efficient way to grab the id incase of a redirect.

Why not just always pass everything to index.php?

PHP is a lot better at manipulating strings than .htaccess

The -f line already takes care of existing static files. (And -d for directories)


RewriteRule ^(.*)$ /index.php?id=$1 [L,QSA]

This rule matches and captures everything.