I have Apache 2 installed on my system. I have uncommented the load rewrite module line in the httpd.conf file. I have an htaccess file with these simple lines:
[code]RewriteEngine On RewriteRule /Index$ /index.shtml[/code]
But /Index still returns 404. I don’t get it. What’s missing?
@ScleppelJul 07.2006 — #In .htaccess files RewriteRule patterns don't start with a /: Options +FollowSymLinks
RewriteEngine On
RewriteRule ^Index$ /index.shtml
If that doesn't work, you might need [url=http://httpd.apache.org/docs/2.0/mod/core.html#allowoverride]AllowOverride[/url] set to All in the [url=http://httpd.apache.org/docs/2.0/mod/core.html#directory]<Directory>[/url] block for your document root.
@FeelLikeANutauthorJul 07.2006 — #Thanks! Taking off that slash seemed to do the trick. Now, however, I can't get deeper directory rewrites to work.RewriteRule ^Examples/NoGraphics$ examples/no-graphics.shtmlThis returned a 404 page. I also tried putting an htaccess file in the [i]examples[/i] directory itself:RewriteRule ^NoGraphics$ no-graphics.shtmlThis didn't work either, however. Any thoughts?
@ScleppelJul 07.2006 — #I don't see any problems with the rules. Check that the file exists and that you're typing it in right. Does the You could try [b]/[/b]examples/... too.
This works fine for me: Options +FollowSymLinks -MultiViews
@FeelLikeANutauthorJul 07.2006 — #I definitately have it in right. I even copy-pased the directory- and file name to make sure there were no typos. I tried with and without the initial slash.
Is there something else I can try? Some other piece of information you can use?
Perhaps this version of Apache has a bug? It is 2.2.2. Perhaps you could download and install that version and see if everything still works the same.
@ScleppelJul 07.2006 — #Right, it seems to be a case problem because of the directory of the same name, but different case.
You can either use a lowercase "e" in the RewriteRule (you can still use an uppercase "e" in the URI) RewriteRule ^examples/NoGraphics$ /examples/no-graphics.shtml [L] or the NC (No Case) flag: RewriteRule ^Examples/NoGraphics$ /examples/no-graphics.shtml [NC,L]
@FeelLikeANutauthorJul 07.2006 — #The no case flag did the trick, though I don't quite understand why it would be necessary -- the URL itself had the same uppercase letters. But whatever, I guess. It works.
@ScleppelJul 07.2006 — #It's probably a combination of windows being case insensitive and mod_rewrite working after the file has been determined.
So first Apache is trying to find the real file. It finds the directory /examples and changes the case of it's (internal?) request_uri variable because that's what exists. Then it doesn't find the file (but that doesn't matter, it goes through mod_rewrite anyway) and the request goes to mod_rewrite.
Now when mod_rewrite applies the pattern, the cases don't match: ## - - [07/Jul/2006:22:03:03 +0100] [##][##] (3) [perdir C:/server/Apache2.2/htdocs/] applying pattern '^Examples/NoGraphics$' to uri 'examples/NoGraphics' and you get a 404. Change the "E" or add the NC flag, and it matches.