0

请有人看看我的 .htaccess 代码以帮助确定问题所在。

我正在尝试将所有 example.php、example.html 和 example.htm URL 修改为 index.php?filename=example.html

Options +FollowSymLinks

<IfModule mod_rewrite.c>

   RewriteEngine On

   RewriteRule ^(index\.php) - [L]

   RewriteRule ^([^/\.]+).(php|html|htm)$ index.php?filename=$1.html&%{QUERY_STRING} [L]

</IfModule>

当我输入像 example.html 这样的 URL 时,我被带到默认的 404 而不是 index.php

4

2 回答 2

1

我暂时没有使用 apache .hatacces,但试试这个:

RewriteEngine On
RewriteCond %{REQUEST_URI} !^/index\.php$
RewriteCond %{REQUEST_URI} !^.*/(css|img|js)($|/.*$) [NC]
RewriteRule ^(.*)$ /index.php?filename=$1&%{QUERY_STRING} [L]

基本上,您需要确保该 URL 还没有 index.php。你可以用 RewriteCond 来完成它。

将所有内容重定向到 index.php 后,将文件名作为参数传递。

你可以像这个例子一样为 RewriteCond 添加更多例外,所有带有 /css、/js、/img 的内容都不会传递给这个规则。

你可以检查这个线程:使用 .htaccess 通过 index.php 重新路由所有请求,除了一组请求

于 2013-05-23T20:25:18.053 回答
1

尝试:

Options +FollowSymLinks
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?filename=$1 [L,QSA]
</IfModule>
于 2013-05-23T21:05:42.357 回答