Forum Moderators: phranque
I've been trying to get this rewrite rule to do as I want, but it doesn't like to cooperate with me. :(
I'm trying to get my .ASP pages to "look" like this:
[myproject.tld...]
but I also need it to work if you just write:
[myproject.tld...]
Right now I'm using this:
RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule ^(.*)$ $1.asp [L]
This works, but only without the endslash, it just removes the .asp.
I've also tried with:
RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule ^(.*)/?$ $1.asp [L]
and:
RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule ^(.*?)/?$ $1.asp [L]
but I just keep getting a 500 error, and the errorlog says maxredirects has been reached.
Thanks in advance for any help
But this still does not work, when I tried your rule it gave me a 404. Could this be because of the "!" in front of the "-f"? Does it think that the input string is actually a dir, and does not find it?
If I remove the "!", this works:
[something.tld...]
but not:
[something.tld...]
But let's examine what the code I posted actually should do:
# IF the requested resource does NOT exist as a file with a .asp extension
RewriteCond %{REQUEST_FILENAME}.asp !-f
# THEN rewrite any request (with optional trailing slash) to same URL-path with trailing ".asp"
RewriteRule ^(.*)/?$ $1.asp [L]
# IF the requested resource does NOT exist as a directory
RewriteCond %{REQUEST_FILENAME} !-d
# THEN rewrite any request (with optional trailing slash) to same URL-path with trailing ".asp"
RewriteRule ^(.*)/?$ $1.asp [L]
Jim
What I want this rewrite rule to do is:
IF the requested resource exists with a .asp extension
THEN rewrite any request (with optional trailing slash) to same URL-path without trailing ".asp"
At least I think that explains it. If my logic "skills" above failed, I'll try to explain it better like so:
If I write [mydomain.tld...] (or without the last slash) I want to get a file named something.asp, tho of course, I want it to display in the adressbar like: [mydomain.tld...] (or without the slash)
The requested file is a .asp, I just want it to "look" like they are all directories.
Do you follow me, or I'm not making any sense?
I have a bunch of other rules that rewrites the forum queries et cetera, they all look like this, but with filename variations (they work fine with or without a trailing slash):
RewriteCond %{REQUEST_URI} ^/thread([0-9]+)/?$
RewriteRule ^ /forum_posts.asp?%1 [L]
(I don't think at least) they depend on the first rule, that I'm having problems with:
RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule ^(.*)$ $1.asp [L]
EDIT: This is the error from the log, it's always the same:
[Mon Aug 22 23:24:45 2005] [error] [client XXX.XXX.XXX.XXX] mod_rewrite: maximum number of internal redirects reached. Assuming configuration error. Use 'RewriteOptions MaxRedirects' to increase the limit if neccessary.
RewriteCond %{REQUEST_URI} !\.asp$
RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule ^(.*)$ $1.asp [L]
Jim
That rule works with:
[mydomain.tld...]
but when I try:
[mydomain.tld...]
I get a 404, telling me it didn't find /something/.asp on the server.
Here is the log:
[Tue Aug 23 01:12:46 2005] [error] [client XXX.XXX.XXX.XXX] File does not exist: /dir/dir/dir/dir/mydomain.tld/something/.asp
RewriteCond %{REQUEST_URI} !\.asp$
RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule [b]^(.*)/?$[/b] $1.asp [L]
There are common problems that make RewriteConds testing REQUEST_FILENAME fail when they should match, but I don't know of any problems that would make them match when they should fail... Strange.
Jim
Try flushing your browser cache (Delete all Temporary Internet Files) after any change to your code, and test again.
Jim
The errorlog says:
[Tue Aug 23 14:58:17 2005] [error] [client XXX.XXX.XXX.XXX] File does not exist: /dir/dir/dir/dir/mydomain.tld/something/.asp
RewriteCond %{REQUEST_URI} !\.asp$
RewriteCond %{REQUEST_FILENAME}.asp -f
RewriteRule ^([^/]+)/?$ $1.asp [L]
Jim