Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/jpa/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP中的URL重写导致问题_Php_Apache_.htaccess_Mod Rewrite - Fatal编程技术网

PHP中的URL重写导致问题

PHP中的URL重写导致问题,php,apache,.htaccess,mod-rewrite,Php,Apache,.htaccess,Mod Rewrite,这是我的.htaccess: <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ profile.php?user=$1 [L,QSA] </IfModule>

这是我的.htaccess:

<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteCond %{REQUEST_URI} !=/favicon.ico
  RewriteRule ^(.*)$ profile.php?user=$1 [L,QSA]
</IfModule>
这是我的重定向部分(我想可能会有帮助)

但它让我转向:

http://localhost/PHP/Projects/HassanTech/pages/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/profile/Hassan
当我尝试访问

http://localhost/PHP/Projects/HassanTech/pages/profile
我想要我的链接:

http://localhost/PHP/Projects/HassanTech/pages/profile?user=Hassan


My.htaccess文件位于pages文件夹中,profile.php位于pages文件夹中。希望您能帮助我。

将标题重定向更改为使用
/
,您将留在同一目录中,从而解决您的问题:

header("Location: ./" . $us);

这把戏是为我做的

URL现在运行良好,但我得到“此网页有重定向循环”,无法访问该网站。这是因为您正在创建一个无限循环。首先,你可以说(通过你的
重写规则
)“我希望所有像
/pages/profile/Hassan
这样的链接指向
pages/profile.php?user=Hassan
”。然后你会说(在你的PHP中),“好吧,如果我找不到具有$\u GET[“user”]值的用户,或者如果$\u GET[“user”]未定义,然后重定向到/pages/profile/Hassan,该页面已经是您所在的页面…因此存在无限循环。您需要更改检查用户的方法,或者修改您的第一个
(如果
条件)。在您发布的另一个问题上发布了答案,这是否与同一问题相关?
http://localhost/PHP/Projects/HassanTech/pages/profile/Hassan
header("Location: ./" . $us);
RewriteEngine On
RewriteRule ^pages/profile/([^/]+)/?$ pages/profile.php?user=$1 [L,NC,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]