1

Here is the .htaccess file

RewriteEngine on
RewriteCond $1 !^(index\.html|index.php|administrator|system|template|js|lib|favicon\.ico|robots\.txt)
RewriteRule ^(.*)$ /index.html?tpl=$1 [L]


Options +FollowSymlinks

However what is happening is that all the following folders wont allow me to go into them and view a PHP file.

|administrator|system|template|js|lib

I thought by putting the files in RewriteCond that it would allow a user to still go to http://example.com/news/happy which then would go to the index.php?tpl=etc etc but it has stopped me from going into any subdirectory like

http://example.com/system/index.php

4

2 回答 2

1

我不知道这是否适合你。但我所做的是添加此规则以加载对任何没有 .php 结尾的 .php 文件的调用。你可以同时调用这两个,有或没有那个结尾。

例如,您可以调用my_url.com/myfolder/myfile它,它会使用友好的 URL 加载myfile.php

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
于 2012-04-30T06:08:26.390 回答
0

我想建议您先阅读有关 mod rewrite 的内容

1 - 将该行放在顶部

 Options +FollowSymlinks

该行要求您的服务器遵循符号链接,但我建议您使用更安全的选项“SymLinksIfOwnerMatch”

资源:

http://httpd.apache.org/docs/2.2/mod/core.html#options#FollowSymLinks

RewriteEngine on

启用或禁用运行时重写引擎

来源: http ://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteengine

 RewriteCond $1 !^(index\.html|index.php|administrator|system|template|js|lib|favicon\.ico|robots\.txt)

干得好 。该规则要求 Web 服务器添加重写条件以忽略正则表达式中列出的所有内容

我也为你添加了正则表达式解释

 ! 

不等于 ^ 开头

 RewriteRule ^(.*)$ /index.html?tpl=$1 [L]

您要求将其他所有内容写入 index.html?tpl=$1 ** 我认为您的意思是 index.php 我会假设您不需要查询字符串

我想建议使用更好的方法来处理排除

 RewriteEngine On
 Options +FollowSymLinks
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_URI} !(index\.html|index.php|administrator|system|template|js|lib|favicon\.ico|robots\.txt)
 RewriteRule ^(.*)$ /index.html?tpl=$1 [L]
于 2018-03-07T01:10:34.800 回答