清理网址错误404

时间:2014-08-19 13:19:06

标签: php apache .htaccess

只想在我的htaccess中自定义错误404。问题是当用户转到错误404页面时。与其他人相比,URL不干净。 URL看起来像这些index.php?page = page-not-found ..我怎样才能使它成为http://example.com/page-not-found.htmhttp://example.com/page-not-found/ ???顺便说一句,看看我的代码。

Options All -Indexes
RewriteEngine On

ErrorDocument 404 http://example.com/index.php?page=page-not-found

RewriteRule ^([^/]*)\.htm$ /website/index.php?page=$1 [L,QSA]

RewriteRule ^([^/]*)/lesson/([^/]*)\.htm$ /thesis/index.php?page=$1&lesson=$2

任何想法的人?顺便说一句,谢谢..

2 个答案:

答案 0 :(得分:2)

http://指令中删除404,以避免服务器为404完全重定向:

Options All -Indexes
RewriteEngine On

ErrorDocument 404 /index.php?page=page-not-found

RewriteRule ^([^/.]+)\.htm$ /website/index.php?page=$1 [L,QSA]

RewriteRule ^([^/]+)/lesson/([^/.]+)\.htm$ /thesis/index.php?page=$1&lesson=$2 [L,QSA]

答案 1 :(得分:-1)

Please try this one.First remove your extensions from all files and try this one

    ErrorDocument 404 /404.php

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^p/([0-9]+)$ /p.php?photo=$1 [QSA,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(Joe|Mao|Napoleon|Gandi)$ /profile.php?username=$1 [QSA,L,NC]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)$ /$1.php [QSA,L]
相关问题