我正在使用apache处理.htaccess。
我希望能够键入这样的URL:
example.com/bob
我想将URL重写为
example.com/index.php?c=bob
我也不希望它影响真实的文件和正常加载它们
example.com/account.php
除此之外,我还想重写没有.php 的真实文件
example.com/account
到目前为止,我一直在关注index.php?c=bob任务。到目前为止,我的.htaccess 中有这个
RewriteCond $1 !^(index.php|account.php|robots.txt)
RewriteRule ^(.*)$ /index.php?c=$1 [L]
我想到的繁重的工作解决方案是在上面的第1行列出我的所有文件,我正在寻找一种更有效的方式
请您尝试以下操作。
RewriteEngine ON
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)/?$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ index.php?c=$1 [L]