404 not found page not working with my .htaccess

2019-03-21 15:24发布

I have below .htaccess on the server with the not found page rules but it doesn't seems to work. Any idea?

RewriteEngine on
RewriteRule ^article_detail/([a-zA-Z0-9_-]+)/([0-9]+)\.html$ article_detail.php?article_det=$2
Options +FollowSymLinks
ErrorDocument 404 http://www.example.com/main/404_not_found.html


# compress text, HTML, JavaScript, CSS, and XML

<IfModule mod_ext_filter.c>
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
# remove browser bugs
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
</IfModule>

5条回答
姐就是有狂的资本
2楼-- · 2019-03-21 15:59

Have you tried ErrorDocument 404 /main/404_not_found.html?

Just incase you have something interfering with your URL (not sure if that is your complete htaccess)? I usually don't put the whole URL in although technically you can.

Also can you access the 404 page directly?

查看更多
闹够了就滚
3楼-- · 2019-03-21 16:05

In your apache configuration, in the Directory section of your website, be sure that you are allowed to override the FileInfo directive.

Somthing like

AllowOverride FileInfo

http://httpd.apache.org/docs/current/mod/core.html#errordocument

查看更多
爷、活的狠高调
4楼-- · 2019-03-21 16:06

Try to uncomment line from httpd.conf in apache configuration.

#LoadModule rewrite_module modules/mod_rewrite.so

is uncommented:

LoadModule rewrite_module modules/mod_rewrite.so

Also restart apache

查看更多
老娘就宠你
5楼-- · 2019-03-21 16:17

I'm assuming you're using Apache rather than IIS;

  1. Ensure you have mod rewrite enabled (You can do this by locating the line below in the httpd.conf file (usually within the /conf/ directory This maybe different if you're using shared hosting and removing the semi colon from the start of the line)

    ;LoadModule rewrite_module modules/mod_rewrite.so

  2. Find the relevant directory tag for your www root and change AllowOverride None to AllowOverride All

  3. Create an .htaccess file within the root directory (If one doesn't exist)

  4. You'd need to insert something that looks like this;

    ErrorDocument 500 /errordocs/500.html

    ErrorDocument 404 /errordocs/404.html

    ErrorDocument 401 /errordocs/401.html

    ErrorDocument 403 /errordocs/403.html

    • Instead of ErrorDocument 404 /errordocs/404.html you could also do ErrorDocument 404 http://www.yourdomain.com/errordocs/404.html or even just display a simple message ErrorDocument 404 "Sorry can't allow you access today"

    • If you have any trouble the Apache Manual (ErrorDocument Directive) should help you out further.

In your case make sure AllowOverride All is on, your editing the .htaccess file in the root and make sure you can hit the URL for the error page, if there's nothing at the URL that you specify Apache will return the default 404.

查看更多
混吃等死
6楼-- · 2019-03-21 16:17

Try to change the line by ErrorDocument 404 http://www.google.com

If that works, that mean that the path you are using was misconfigure. I don't know your directory structure so I can give you the good code to write.

I don't think it's an .htaccess error because you'll get a 500 Internal error if it is.

If this tricks does not work, that means something redirecting inside your apache configuration.

查看更多
登录 后发表回答