0

I've tried to look this up every way I could and couldn't find a direct answer to this particular question. I have some .htaccess rewrite rules for some friendly URLs and want to handle 404 errors that may occur in various ways.

First, here are a couple of the rewrite rules:

RewriteRule ^newsite/designer/([A-Za-z0-9_.%&-]+).html/?$ newsite/catalog.php?m=$1 [NC,L,B,QSA]
RewriteRule ^newsite/search/([A-Za-z0-9_.%'&-]+)/?$ newsite/catalog.php?kw=$1 [NC,L,B,QSA]

I would like to direct 404 errors for search/ differently than 404 error within designer/. Each having their own destination. But since these are not actual directories I can't just put a separate .htaccess file in the directoies.

Ultimately I want to have all other 404 not expressly redirected to go to the catchall, like

ErrorDocument 404 /index.php

Is this possible and how?

4

2 回答 2

0

您可以使用这些重写规则:

RewriteEngine On

# specific 404 handlers
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^newsite/search/ /newsite/404.php?base=search [L,NC,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^newsite/designer/ /newsite/404.php?base=designer [L,NC,QSA]

RewriteRule ^newsite/designer/([A-Za-z0-9_.%&-]+).html/?$ newsite/catalog.php?m=$1 [NC,L,B,QSA]
RewriteRule ^newsite/search/([A-Za-z0-9_.%'&-]+)/?$ newsite/catalog.php?kw=$1 [NC,L,B,QSA]

# generic 404 handling:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^newsite/designer/ /newsite/404.php [L,NC]
于 2014-06-27T18:48:01.697 回答
0

您可能可以<Location>在配置中使用部分:

<Location /newsite/designer>
    ErrorDocument 404 wherever
</Location>

但是,可能在很多情况下您可能无法获得 404(如果请求与RewriteRules 匹配并且它在脚本中您找不到匹配项),具体取决于您的脚本的工作方式。

于 2014-06-27T14:53:52.430 回答