所以我在我的HTACCESS中使用了这个代码,这很好,因为如果访问者使用.PHP文件扩展名进入页面,它首先从我的页面中删除.PHP文件扩展名,然后允许页面加载而不用扩展名。 (所以这只是url)
# REMOVE FILE EXTENSIONS RewriteEngine On # browser requests PHP RewriteCond %{THE_REQUEST} ^[AZ]{3,9} /([^ ]+).PHP RewriteRule ^/?(.*).PHP$ /$1 [L,R=301] # check to see if the request is for a PHP file RewriteCond %{REQUEST_FILENAME}.PHP -f RewriteRule ^/?(.*)$ /$1.PHP [L]
它工作的很好,但后来我遇到了问题在网页上: http : //www.CyberBytesInc.com/contact,因为我有一个表单调用一个.PHP文件发送:
<form id="request-form" action="resources/script/question-send.PHP" method="post">
上面的htaccess代码删除了这个文件的.PHP文件,我得到了错误代码“不允许直接访问这个页面”。 这是脚本里面,这是
} else { die('Direct access to this page is not allowed.'); }
一旦我从htaccess中删除这个,然后开始工作:
rewrite_mod已启用,但.htaccess不起作用
.htaccess简短和友好的url
GoogleredirectURI不允许使用片段url的解决方法
.htaccess – 将多个子目录重写为root
.htaccess基于HTTP_REFERER的redirect是空的
# browser requests PHP RewriteCond %{THE_REQUEST} ^[AZ]{3,R=301]
但是,如果将.PHP放在页面的末尾(Google的大部分文件扩展名都是索引的,而我试图删除这个扩展名),那么我不会去除文件的扩展名。
我想如果我能以某种方式使得它的htaccess的代码工作除了从我的/资源/脚本/文件夹访问文件时,我不知道最好的方法来解决这个问题。
你现在可以去这个网站看看,因为这个,它不工作。 目前我可能会删除上面提到的代码行,所以我的表单是最起码的工作。 所以,如果你查看网站和表单工作,这是因为我删除了上面的.htaccess,直到我弄清楚如何成功地在那里。
谢谢!
<?PHP // Get email address $email_address = '[email protected]'; // Ensures no one loads page and does simple spam check if( isset($_POST['name']) && empty($_POST['spam-check']) ) { // Declare our $errors variable we will be using later to store any errors $error = ''; // Setup our basic variables $input_name = strip_tags($_POST['name']); //required $input_email = strip_tags($_POST['email']); //required $input_subject = strip_tags($_POST['subject']); $input_message = strip_tags($_POST['message']); //required // We'll check and see if any of the required fields are empty if( strlen($input_name) < 2 ) $error['name'] = '<label for="question-name">Please enter your <b>Name</b></label>'; if( strlen($input_message) < 5 ) $error['message'] = '<label for="question-message">Please leave a longer <b>Message</b></label>'; // Make sure the email is valid if( !filter_var($input_email,FILTER_VALIDATE_EMAIL) ) $error['email'] = '<label for="question-email">Please enter a valid <b>Email Address</b></label>'; // Set a subject & check if custom subject exist if( $input_subject ) $subject = "(Question) - $input_subject"; else $subject = "(Question) - No Subject"; // $message .= "$input_messagen"; $message .= "nn---nThis email was sent by $input_name from $input_email"; // Now check to see if there are any errors if( !$error ) { // No errors,send mail using conditional to ensure it was sent if( mail($email_address,$subject,$message,"From: $input_email") ) { echo '<p class="success"><b>EMAIL SENT SUCCESSFULLY.</b><br />' . "Dear $input_name," . 'thank you for contacting CyberBytes Inc. Please allow us <b>24-48</b> hours to review your request and get back to you. If you need a response sooner,please contact us via telephone at (716) 876-1824.<br /><br /><b>Please verify that this is your correct Email Address:</b><br />' . "Email Address: <i>$input_email</i>" . '<br /><br /><span class="red"><b>PLEASE NOTE:</b></span><br /> If we do not respond to your request within a reasonable amount of time,please give us a call as there may have been an error on our end with your request.</p>'; } else { echo '<p class="error">There was a problem sending your email! Please give us a call at (716) 876-1824 as there seems to be an error on our end with the form.</p>'; } } else { // Errors were found,output all errors to the user $response = (isset($error['name'])) ? $error['name'] . "n" : null; $response .= (isset($error['email'])) ? $error['email'] . "n" : null; $response .= (isset($error['message'])) ? $error['message'] . "n" : null; echo "<p class='error'>$response</p>"; } } else { die('Direct access to this page is not allowed.'); }
Mod重写目录检查
为什么如果我在我的htaccess的规则中join“ – ”破折号不起作用?
Apache /国防部重写:路由一切index.PHP?
在子目录中如何使cakePHP 2.x出现在根目录下(用htaccess中的mod_rewrite)?
更改您的规则以跳过POST请求:
# browser requests PHP RewriteCond %{REQUEST_METHOD} !POST RewriteCond %{THE_REQUEST} ^s/([^ ]+).PHP RewriteRule ^/?(.*).PHP$ /$1 [L,R=301]
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。