php - .htaccess modrewrite 无法正常工作?

标签 php mysql .htaccess testing url-rewriting

再回来(你会很高兴知道我在你的帮助下慢慢取得进展!)遇到了另一个障碍,这次是 .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

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

最佳答案

这些不是有效的规则

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

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

尝试将它们更改为:

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

关于php - .htaccess modrewrite 无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21881977/

相关文章:

php - SQLSTATE[42S22] : Column not found: 1054 Unknown column in lumen

php - htAccess 重定向除 Assets 文件夹之外的所有 .php

php - 错误号 : 150 Foreign key constraint is incorrectly formed

php - Yii2:模块中的独立操作

php - php中的隐式类变量声明?

php - 在 WooCommerce 中,在所有订单的运输详细信息下添加新的输入字段,仅向管理员显示

php - 代码重用 : Common Functions - Laravel

mysql - 在 MySQL 上以嵌套方式进行内部连接

php - Codeigniter Htaccess 和 URL 重定向问题

.htaccess - 使用.htaccess时如何使mod_rewrite *不*执行主目录扩展