如何使用htaccess将不可用的页面重定向到404?

时间:2014-08-26 10:50:15

标签: apache .htaccess

我已粘贴我的htaccess文件代码如何可能重定向无法文件/文件夹,页面,无效搜索不匹配搜索404.When我喜欢ffsdfdfsdf之后的任何事情或者它可能是我看到空白页面的任何内容。我知道问题出在htaccess文件中。

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/jpg "access 1 month”
ExpiresByType image/jpeg "access 1 month”
ExpiresByType image/gif "access 1 month”
ExpiresByType image/png "access 1 month”
ExpiresByType text/css "access 1 month"
ExpiresByType text/html "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType text/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 month”
ExpiresDefault "access 1 month"
</IfModule>
RewriteEngine on 
RewriteCond %{HTTP_HOST} !^floristnz\.co.nz$ [NC]
RewriteRule ^(.*)$ http://floristnz.co.nz/$1 [R=301,L]
RewriteRule ^(florist)/(.*)$ florist_page.php?florist_name=$2 [L,NC]
RewriteRule ^(florist)$ florist.php [L]
RewriteRule ^(Buy-Flowers)$ Flowers.php [L]
RewriteRule ^(New-Baby)$ New-Baby.php [L]
RewriteRule ^(Christmas-Flowers)$ Christmas-Flowers.php [L]
RewriteRule ^(Flowers-With-Vases)$ Flowers-With-Vases.php [L]
RewriteRule ^(Gift-Baskets)$ Gift-Baskets.php [L]
RewriteRule ^(Plants)$ Plants.php [L]
RewriteRule ^(Bouquets)$ Bouquets.php [L]
RewriteRule ^(Arrangements)$ Arrangements.php [L] 
RewriteRule ^(Roses)$ Roses.php [L]
RewriteRule ^(Sympathy)$ Sympathy.php [L]
RewriteRule ^(Celebration)$ Celebration.php [L]
RewriteRule ^(Tropical-Flowers-And-Gifts)$ tropical-flowers-and-gifts.php [L]
RewriteRule ^(Top-Ten-Online-Flowers)$ top-ten.php [L]
RewriteRule ^(Gifts)$ Gifts.php [L]
RewriteRule ^(contact)$ contact.php [L]
RewriteRule ^(article)/(.*)$ article.php?article_name=$2 [L,NC]
RewriteRule ^(florists)/(.*)$ florist_listing.php?category_url=$2 [L,NC]
RewriteRule ^(articles)/(.*)/([0-9]+)$ article_listing.php?category_url=$2&page=$3 [L,NC]
RewriteRule ^(articles)/(.*)$ article_listing.php?category_url=$2 [L,NC]
RewriteRule ^(page)/(florist-article)$ florist_article.php [L,NC]
RewriteRule ^(css)/(.*)$ css/$2 [L,NC]
RewriteRule ^(images)/(.*)$ images/$2 [L,NC]
RewriteRule ^()$ index.php [L]
RewriteRule ^(index.php)$ index.php [L,NC]
RewriteRule ^([a-z-_]+)$ static_page.php?url=$1 [L,NC]
Redirect 301 /florist/Oneroa http://floristnz.co.nz/florist/Oneroa%20Waiheke
ErrorDocument 404 /404.html/{ee:404}
# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddDefaultCharset utf-8

1 个答案:

答案 0 :(得分:0)

在你的脚本中:

  • article.php
  • florist_page.php
  • florist_listing.php
  • static_page.php

您需要检查传入的参数,如果他们没有指向有意义的内容(如现有的花店或现有页面),则返回404。

header("HTTP/1.0 404 Not Found");