开发者

URL Rewrite problem

I did a .htaccess that change urls like www.site.com/sell.php to www.site.com/sell. Sell page exists at my / and it works fine. The problem is when i try something like www.site.com/sadasdasdasdadsdfgfds, because "sadasdasdasdadsdfgfds" doesn't exist. I receive a 500 Apache's error.

This is my .htaccess file:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /$0.php

How could I fix it? 开发者_StackOverflow中文版Thank you guys.

UPDATE: Worked! Thanks guys! Now how do I redirect user to a 404 custom error page?


You have checks to make sure the file doesn't exist. You also have to make sure the corresponding php-file does exist:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* /$0.php


You need to test if the new destination is an existing file:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule .* /$0.php

Otherwise you will get an infinite recursion.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜