开发者

500 error for clean url mod re-write

开发者 https://www.devze.com 2022-12-17 20:10 出处:网络
Thanks to everyone who has helped me with my clean URL quest. I\'m almost there but want to lick this last thing.

Thanks to everyone who has helped me with my clean URL quest. I'm almost there but want to lick this last thing.

.htaccess

RewriteEngine on

#REMOVE THIS LINE ON SITE LAUNCH!
RewriteBase /~accountName/

#Hide .php extensions for cleaner URLS
RewriteCond %{REQUEST_F开发者_如何学PythonILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php

#calendar-expanded REST-ful URLs
RewriteRule ^calendar-expanded(/.*)?$ calendar-expanded.php$1 [L]

Options All -Indexes

<IfModule mod_security.c>
    SecFilterEngine Off
    SecFilterScanPOST Off
</IfModule>

# propagate php.ini file to all sub-directories
suPHP_ConfigPath /home/accountName/public_html/php.ini

my working url

www.example.com/calendar-expanded/4/mother-mother-in-concert/

a broken url

www.example.com/calendar/12/another-band-live/

There is no mod re-write for calendar/ obviously. My question is, do I absolutely need a rule for every page to avoid internal server errors if someone accidentally browses to the wrong page? The broken url is an example of that. I'd really love for the browser to return a 404 error instead.

I'm looking for a cond/rule that will cover "all other" urls except calendar-expanded. Is this doable?

Thanks. (@Gumbo I'm looking hopefully in your direction!)


I could reconstruct this behavior and trace it back to this condition:

RewriteCond %{REQUEST_FILENAME}\.php -f

Here REQUEST_FILENAME does only contain the filesystem path to calendar within the same directory. And that appended with .php is an existing file so the condition is true. But $1 does contain the full requested URL path that is now appended .php. This keeps repeating until the internal counter exceeds its limit.

A solution to that is to use %{REQUEST_FILENAME}.php in the substitution as well:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php


Could you create a rule that matches everything and just have it at the bottom? The rewrite engine gives precedence to rules based on the order in which they appear in the .htaccess file.

0

精彩评论

暂无评论...
验证码 换一张
取 消