使用htaccess的从URL删除的.php [英] using htaccess to remove .php from URL
本文介绍了使用htaccess的从URL删除的.php的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的网址:的http://localhost/test.php
我使用的:
的.htaccess:
.htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
PHP:
$url = $_GET['url'];
echo var_dump($url);
但我得到了$网址是:NULL NULL NULL NULL NULL NULL
But all I get for $url is:NULL NULL NULL NULL NULL NULL
推荐答案
编辑:调整为同时处理重定向和重写
adjusted to handle both the redirect and the rewrite.
RewriteEngine On
RewriteBase /
# Redirect .php URLs to rewritten URLs
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)\.php$ $1 [L,QSA,R=301]
# Rewrite URLs for processing by router (index.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L,NC]
您应该排除的RewriteCond%{} REQUEST_FILENAME!-d
的条件,因为它会试图访问一个目录,如果您的网址进行匹配。做URL重写时,可能是不可取的。
You should exclude the RewriteCond %{REQUEST_FILENAME} !-d
condition, as it will attempt to access a directory if your URL matches it. Probably not desirable when doing url rewriting.
的index.php
index.php
$url = isset($_GET['url']) ? $_GET['url'] : null;
var_dump($url);
这篇关于使用htaccess的从URL删除的.php的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文