Warm tip: This article is reproduced from serverfault.com, please click

apache-.htaccess重写隐藏参数并保持文件相同

(apache - .htaccess rewrite hidden parameter and keep files the same)

发布于 2020-11-29 12:09:15

我正在使用Apache使用.htaccess。

我希望能够输入如下网址:

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行中列出我的所有文件,我正在寻找一种更有效的方法

Questioner
Jake
Viewed
0
RavinderSingh13 2020-11-30 01:47:21

你可以尝试以下吗?

RewriteEngine ON
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)/?$ $1.php [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ index.php?c=$1 [L]