Forum Moderators: phranque
The code I have works, but it does it unconditionally.
For instance, it redirects file1.html to /app.php?file=file1 even though the file exists.
Code:
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME}!-d
RewriteCond %{REQUEST_FILENAME}!-f
RewriteRule ^([^/]+)\.shtml$ /app.php?file=$1 [L,R=301]
RewriteRule ^([^/]+)\.html$ /app.php?file=$1 [L,R=301]
I'm not sure if the!-d and f are necessary, or if this is even possible, though.
EDIT: And there's a topic about the same thing on the same page... Sorry mods, you can delete this. Guess I should have looked harder...
If you wish both of your rules to require the NOT(file-exists) condition, then you'll need to construct the code differently.
For example:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)\.s?html$ /app.php?file=$1 [L,R=301]
Jim
[edited by: jdMorgan at 12:37 am (utc) on Nov. 21, 2005]
You can combine them and use one rule:
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^.]+)\.s?html$ /app.php?file=$1 [L,R=301]
I removed the directory check, because you are only evaluating requests with extentions, which should never be a directory... A request that ends in a / will not match your rule.
Also changed the expression to match 'everything that is not a .(dot) followed by a .(dot)'
Hope this helps.
Justin