Mod rewrite mod#U rewrite-某些被重写的请求应生成404但不';T

Mod rewrite mod#U rewrite-某些被重写的请求应生成404但不';T,mod-rewrite,redirect,http-status-code-404,Mod Rewrite,Redirect,Http Status Code 404,我一直致力于为我的网站创建seo友好的URL,并成功地使用以下规则: RewriteEngine on RewriteBase / #redirect non www to www RewriteCond %{HTTP_HOST} ^example.co.uk [NC] RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301] # Redirect any request with page=var to /var/ format Re

我一直致力于为我的网站创建seo友好的URL,并成功地使用以下规则:

RewriteEngine on
RewriteBase /

#redirect non www to www
RewriteCond %{HTTP_HOST} ^example.co.uk [NC]
RewriteRule ^(.*)$ http://www.example.co.uk/$1 [L,R=301]

# Redirect any request with page=var to /var/ format
RewriteCond %{QUERY_STRING} ^page=(.+[^/])$ [NC]
RewriteRule ^index\.cfm$ http://%{HTTP_HOST}/%1/? [R=301,L,NC]

# If not an existing file or directory rewrite any request
# to page var.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+[^/])/$ index.cfm?page=$1 [QSA,L]
我的问题是,由于最后一条规则(我认为),任何根目录请求都会被放入一个友好的url中,比如
/pagethattotpointanywhere/
,不管它是否指向任何地方。现在我很乐意使用404,但它没有这样做,它只是显示主页

我还尝试添加了一条总括404规则:

# 404 files that don't exist
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .+ /notfound.html [R=404,L,NC]
但这也使得所有友好的URL 404成为可能

有人能解释一下我哪里出了问题吗

  • 当Apache找不到文件时,使用
    ErrorDocument 404/notfound.cfm
    显示未找到的错误页面(用您的文件替换
    notfound.cfm

  • index.cfm
    中,如果
    page
    参数的值未知(例如
    pagethattotpointanywhere
    ),则显示404错误页面(使用与
    notfound.cfm
    相同/类似的代码)。考虑到您的重写规则以及您正在检查此处显示的页面,这是一个正确的位置。许多产品/框架以类似的方式工作(例如:WordPress)

  • 同时使用#1和#2。数字#2将用于1文件夹深度URL(例如
    /meow/
    ),而#1将捕获任何其他URL(例如
    /meow/kitten/
    /meow/wuf/oink.css

  • 当Apache找不到文件时,使用
    ErrorDocument 404/notfound.cfm
    显示未找到的错误页面(用您的文件替换
    notfound.cfm

  • index.cfm
    中,如果
    page
    参数的值未知(例如
    pagethattotpointanywhere
    ),则显示404错误页面(使用与
    notfound.cfm
    相同/类似的代码)。考虑到您的重写规则以及您正在检查此处显示的页面,这是一个正确的位置。许多产品/框架以类似的方式工作(例如:WordPress)


  • 同时使用#1和#2。数字2将用于1文件夹深度的URL(例如
    /meow/
    ),而1将捕获任何其他URL(例如
    /meow/kitten/
    /meow/wuf/oink.css
    )。

    好的,听起来像个计划,再次感谢懒人,我将朝那个方向前进。好的,听起来像个计划,再次感谢懒人,我将朝那个方向前进。