如果没有找到页面htaccess的重写规则失败 [英] htaccess RewriteRule fails if page not found
问题描述
我想用户重写规则
在我的的.htaccess
文件重定向example.com/page示例.COM / page.php(或添加的.php
到不具有扩展名。任何请求的文件
我想:
RewriteEngine叙述上
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!(。*)\。PHP
的RewriteCond%{REQUEST_FILENAME} \ PHP -f
重写规则^([^ /] +)$ $ 1.PHP [R]#我也试过^(。+)$无影响
从<一个href="http://stackoverflow.com/questions/7630996/spoofing-a-404-not-found-error-with-htaccess">"Spoofing" 404未找到错误与的.htaccess
我想这没有其他重写规则
在我的htaccess的,但它仍然只是通过的ErrorDocument 解析为404错误页面code>。所有其他规则我尝试使用还可以得到完全跳过,如果找不到请求的页面。任何规则,我指定的作品如果被请求的URL解析到一个现有的页面或目录。
我有一个GoDaddy的共享主机的Linux服务器。我是pretty的肯定,我不能编辑我的httpd.conf文件。
我想知道是否有人能告诉我为什么我的重写规则
,则忽略当原来的请求不是一个文件或目录 - 当它不存在
感谢您的任何帮助。
修改:
我现在看到的,如果我去mysite.com/index.php~~V重写规则的作品。如果我去mysite.com/index~~V重写规则不起作用。如果我去一个不存在的所有页面 - mysite.com/asdfasdfsadf然后我重写规则运作。因此,它不但不能在现有的URL的扩展名的版本。
RewriteEngine叙述上
的RewriteBase /
的RewriteCond%{} REQUEST_FILENAME!-f
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!(。*)\。PHP
的RewriteCond%{REQUEST_FILENAME} \ PHP -f
重写规则^(。+)$ $ 1.PHP [R]
I'm trying to user RewriteRule
in my .htaccess
file to redirect example.com/page to example.com/page.php (or add the .php
to any requested file that does not have an extension.
I tried:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !(.*)\.php
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/.]+)$ $1.php [R] #I also tried ^(.+)$ with no effect
from "Spoofing" a 404 not found error with .htaccess
I tried this with no other RewriteRule
s in my .htaccess, but it still just resolves to the 404 error page via the ErrorDocument
. All other rules I try to use also get completely skipped if the requested page is not found. Any rule I specify works if the requested url resolves to an existing page or directory.
I have a Godaddy shared hosting Linux server. I am pretty sure that I cannot edit my httpd.conf file.
I'm wondering if anybody could tell me why my RewriteRule
s are ignored when the original request is not a file or directory - when it doesn't exist.
Thank you for any help.
EDIT:
I now see that if I go to mysite.com/index.php RewriteRule works. If I go to mysite.com/index RewriteRule does not work. If I go to a page that does not exist at all - mysite.com/asdfasdfsadf then my RewriteRule works. So it only fails on the extensionless version of an existing url.
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !(.*)\.php
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.+)$ $1.php [R]
这篇关于如果没有找到页面htaccess的重写规则失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!