Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/apache/8.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
Regex htaccessrewrite和remove.php扩展名_Regex_Apache_.htaccess_Mod Rewrite_Redirect - Fatal编程技术网

Regex htaccessrewrite和remove.php扩展名

Regex htaccessrewrite和remove.php扩展名,regex,apache,.htaccess,mod-rewrite,redirect,Regex,Apache,.htaccess,Mod Rewrite,Redirect,因此,我一直在阅读mod_rewrite,因为我想删除.php扩展名并使URL看起来不同,这样最终用户就不会看到URL中的所有参数 我的目标是: /foo.php?p=bar 看起来像: /foo/bar 其中foo和bar可以是任何东西,数字和字符。 我只处理.php文件,因此它不必处理.html和类似文件。您可以在文档中使用此代码。\u ROOT/.htaccess文件: RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENA

因此,我一直在阅读mod_rewrite,因为我想删除.php扩展名并使URL看起来不同,这样最终用户就不会看到URL中的所有参数

我的目标是:
/foo.php?p=bar
看起来像:
/foo/bar

其中foo和bar可以是任何东西,数字和字符。
我只处理.php文件,因此它不必处理.html和类似文件。

您可以在
文档中使用此代码。\u ROOT/.htaccess
文件:

RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [F]

RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^([^/]+)/?$ $1.php [L]

RewriteCond %{DOCUMENT_ROOT}/$1\.php -f [NC]
RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?p=$2 [L]