Regex htaccessrewrite和remove.php扩展名
因此,我一直在阅读mod_rewrite,因为我想删除.php扩展名并使URL看起来不同,这样最终用户就不会看到URL中的所有参数 我的目标是: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
/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]