【问题标题】:.htaccess modrewrite not working properly?.htaccess modrewrite 无法正常工作?
【发布时间】:2014-02-19 21:37:11
【问题描述】:

再次返回(您会很高兴知道在您的帮助下我正在慢慢取得进展!)遇到另一个障碍,这次是 .htaccess...

我正在尝试这样做,以便您可以访问这样的用户个人资料... site.co.uk/'username' 目前我已将个人资料页面中的代码更改为如下所示...

 <?php 
include 'core/init.php';

if (isset($_GET['username']) === true && empty($_GET['username']) === false) {
$username   = $_GET['username'];

echo $username;
} else {
header('Location: index.php');
exit();
}

?>  

我尝试将以下代码添加到我的 .htaccess 文件中以使其正常工作:

//RewriteEngine On 
RewriteCond %{REQUEST_FILENAME} !=f
RewriteCond %{REQUEST_FILENAME} !=d
RewriteRule ^(.*)$ /userprofile.php?username=$1

问题是,当我尝试访问我的网站时,它会将我发送到虚拟主机提供商 (000webhost.com) 的错误页面。无论我尝试了什么,我都无法让它工作?任何小的编辑都会导致整个网站崩溃?以下是在您上传网站之前,原始 .htaccess 代码已经上传到服务器上的样子(可以正常使用):

<IfModule mod_dir.c>
DirectoryIndex index.php index.html index.htm user_signup.php user_default_page.php index.html index.shtml index.php
</IfModule>

<IfModule mod_deflate.c> 
SetOutputFilter DEFLATE 
</ifmodule> 
<IfModule mod_headers.c>
<FilesMatch "\.(css|js|jpg|jpeg|gif|png|bmp)$">
    Header set Cache-Control "max-age=604800, private, must-revalidate" 
</FilesMatch>
Header set Vary "Accept-Encoding"
</ifmodule>


IndexIgnore *
<FilesMatch .htaccess>
Order allow,deny
Deny from all
Satisfy All 
</FilesMatch> 

<IfModule mod_rewrite.c>
RewriteEngine On 
RewriteCond %{QUERY_STRING} ^thankyou-page=([0-9]*)$ 
RewriteRule ^(.*)$ affilates_redirect.php [L]
</IfModule>

ErrorDocument 404 /404.php

非常感谢任何帮助或建议!谢谢大师!

【问题讨论】:

  • !=d 更改为!-d!=f 更改为!-f,看看是否可行。
  • 我无法相信它是如此简单......非常感谢!
  • 我已将其添加为答案,如果您满意您的问题已解决,请接受它。

标签: php mysql .htaccess testing rewrite


【解决方案1】:

这些不是有效的规则

RewriteCond %{REQUEST_FILENAME} !=f
RewriteCond %{REQUEST_FILENAME} !=d

在这种情况下,fd 是标志,应该以破折号 (-) 而不是等号 (=) 开头。

尝试将它们更改为:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-06-07
    • 2012-08-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多