superjoe30 Posted September 19, 2007 Share Posted September 19, 2007 I'm trying to use mod rewrite with apache. I'm just using this simple code to test it for now: RewriteRule .* test.htm Should be simple - no matter what is requested, pretend it was in fact test.htm that was requested. The problem is it works only if the requested url exists on the server. For example if my root directory contains: blah.txt blah2.txt test.htm and I navigate to http://localhost/stinkycheesebombs It prints 404, when really it should send test.htm to the browser. If I navigate to http://localhost/blah.txt, it does exactly what it's supposed to. It only malfunctions if the file doesn't exist. But the file doesn't have to exist, and in fact it should not exist for what I'm trying to do. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/69883-solved-not-working-when-the-file-doesnt-exist-locally/ Share on other sites More sharing options...
hackerkts Posted September 19, 2007 Share Posted September 19, 2007 I'm not very sure what you're trying to do, is it this? RewriteEngine on RewriteRule ^(.*)$ text.htm Quote Link to comment https://forums.phpfreaks.com/topic/69883-solved-not-working-when-the-file-doesnt-exist-locally/#findComment-351238 Share on other sites More sharing options...
superjoe30 Posted September 19, 2007 Author Share Posted September 19, 2007 I already have RewriteEngine on, I'm not retarded. I forgot to use ^ and $ when I posted on this forum, but not in my .htaccess. The point here, is that simple URL rewrites DO NOT WORK if the requested file does not exist on the server, and the URL rewrites YES DO WORK if the requested file exists on the server. Why would this be? Quote Link to comment https://forums.phpfreaks.com/topic/69883-solved-not-working-when-the-file-doesnt-exist-locally/#findComment-351405 Share on other sites More sharing options...
trq Posted September 19, 2007 Share Posted September 19, 2007 Try.... RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ text.htm [L] Otherwise, post your actual .htaccess file. Quote Link to comment https://forums.phpfreaks.com/topic/69883-solved-not-working-when-the-file-doesnt-exist-locally/#findComment-351504 Share on other sites More sharing options...
superjoe30 Posted September 20, 2007 Author Share Posted September 20, 2007 Figured it out. Quote Link to comment https://forums.phpfreaks.com/topic/69883-solved-not-working-when-the-file-doesnt-exist-locally/#findComment-351923 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.