简体   繁体   English

允许访问CI根目录中的特定php文件

[英]Allow access to a specific php file in CI root

I created a test.php in my root. 我在根目录下创建了一个test.php。 and wanted it to be accessible but its giving me a 404 error. 并希望它可以访问,但给我一个404错误。 Please see below for my .htaccess config. 请参阅下面的我的.htaccess配置。

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,NC,L]

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

I tried adding "RewriteCond $1 !^(test.php)" above the rewriteRule but its still not accessible. 我尝试在rewriteRule上方添加“ RewriteCond $ 1!^(test.php)”,但仍无法访问。 Can anyone give me an advice on how I can make the test.php accessible in a browser, I want to access it in a browser by going to this URL: www.domain.com/test.php 谁能给我一个建议,以使我可以在浏览器中访问test.php,我想通过以下URL在浏览器中访问它:www.domain.com/test.php

Thanks in advance! 提前致谢!

Try this: 尝试这个:

RewriteEngine On
RewriteCond $1 !^(index\.php|images|css|test\.php)
RewriteRule ^(.*)$ ./index.php/$1 [L] 

Every request will be sent to your index.php except those mentioned in RewriteCond, ie, css, images and test.php 除RewriteCond中提到的请求(即CSS,图像和test.php)外,每个请求都将发送到您的index.php。

Replace your first two lines with the following. 用以下内容替换前两行。

RewriteCond %{HTTP_HOST} ^site\.com$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L,NE]

Also your index.php should be accesible with or without that code so it's not needed. 此外,无论是否带有该代码,index.php都应可访问,因此不需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM