无法使用htaccess从index.php获取url作为get参数
这是我的.htaccess文件无法使用htaccess从index.php获取url作为get参数,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,这是我的.htaccess文件 RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?url=$1 [NC,L] index.php文件与.htaccess文件的深度相同,但当我调用 $url = $_GET['url']; 在index.php中。有一条警告说$\u GET s
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?url=$1 [NC,L]
index.php文件与.htaccess文件的深度相同,但当我调用
$url = $_GET['url'];
在index.php中。有一条警告说$\u GET superglobal中没有名为url的索引
请帮助我当您直接转到url或 要解决此问题,您可以在使用“url”之前检查它是否存在:
if (isset($_GET['url']))
$url = $_GET['url'];
else
{
// do nothing, or die()
die('no direct access allowed');
}
问题不是我的htaccess文件,而是我没有在系统中启用mod_rewrite 启用mod_rewrite解决了这个问题。所以
sudo a2enmod rewrite
sudo service apache2 restart
这解决了问题您可以直接从$\u服务器阵列获取此信息,而无需进行任何重写。请将[NC,L]更改为[QSA,L],然后检查您的URL的外观。@AbhikChakraborty我将其更改为否effect@ShikharSubedi:它对哪个URL不起作用?