再回来(你会很高兴知道我在你的帮助下慢慢取得进展!)遇到了另一个障碍,这次是 .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
在这种情况下,f
和 d
是标志,应该以破折号 (-) 而不是等号 (=) 开头。
尝试将它们更改为:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
关于php - .htaccess modrewrite 无法正常工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21881977/