Php Localhost和htaccess

Php Localhost和htaccess,php,.htaccess,codeigniter,Php,.htaccess,Codeigniter,我的sites文件夹中列出了五个目录,它们充当本地服务器上的站点。其中一个站点使用codeigniter进行编码。我违背了自然的文件结构,将应用程序和系统文件夹移到了站点文档根目录之外。我目前拥有运行驻留在公共html中的应用程序所需的index.php文件,以便在测试准备就绪时轻松传输到我的实时站点。当我在本地服务器上时,如何删除URL的所有额外部分 现在我看到的是: localhost/sitename/public\u html/controller 我更愿意对该网站进行设置,以便在我的浏

我的sites文件夹中列出了五个目录,它们充当本地服务器上的站点。其中一个站点使用codeigniter进行编码。我违背了自然的文件结构,将应用程序和系统文件夹移到了站点文档根目录之外。我目前拥有运行驻留在公共html中的应用程序所需的index.php文件,以便在测试准备就绪时轻松传输到我的实时站点。当我在本地服务器上时,如何删除URL的所有额外部分

现在我看到的是:

localhost/sitename/public\u html/controller

我更愿意对该网站进行设置,以便在我的浏览器中打开该网站时,它会显示如下内容:

dev.mysite.com/controller

众所周知,公共html只是一个文件夹

我在htaccess中做什么工作

更新:

sudo nano -w /etc/hosts
在我的mac电脑上,我有一个站点文件夹,它将我的所有站点放在本地服务器上

- Sites
    -site1
        -application
        -public_hml
            index.php
            .htaccess
        -system
    -site2
        -application
        -public_html
            index.php
            .htaccess
        -system
我现在已经在mamp中设置了apache,其中sites是文档根。这就是我应该做的

当我要加载页面的索引文件时,它显示为:

localhost/site1/public_html/index.php
显然,如果我要上传到一个实时服务器,我所要做的就是转到下面的链接,它就会工作。我只是想在上传到实时服务器之前进行本地开发

sitesname.com/index.php

您需要在您的路线中更改它

[yourname youwant]=“控制器/索引”

[yournameyouwant]=“文件夹/控制器/索引”

以下是我使用的一些htaccess

Options +FollowSymLinks
Options -Indexes
DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]


重新启动发动机
重写基/
#删除用户对系统文件夹的访问权限。
#此外,这将允许您创建System.php控制器,
#以前这是不可能的。
#如果已重命名系统文件夹,则可以替换“系统”。
重写COND%{REQUEST_URI}^系统*
重写规则^(.*)$/index.php?/$1[L]
#当应用程序文件夹不在系统文件夹中时
#此代码段阻止用户访问应用程序文件夹
#提交人:Fabdrol
#将“应用程序”重命名为应用程序文件夹名称。
重写cond%{REQUEST_URI}^应用程序*
重写规则^(.*)$/index.php?/$1[L]
#检查用户是否试图访问有效文件,
#例如图像或css文档,如果这不是真的,它会发送
#请求index.php
重写cond%{REQUEST_FILENAME}-F
重写cond%{REQUEST_FILENAME}-D
重写规则^(.*)$index.php?/$1[L]
#如果我们没有安装mod_rewrite,所有404
#可以发送到index.php,一切正常。
#提交人:ElliotHaughin
ErrorDocument 404/index.php

我在WINDOWS上的XAMPP中工作

转到
C:\Windows\System32\drivers\etc\
,然后在文本编辑器中打开名为
hosts
的文件。然后在文件末尾添加这些行

127.0.0.1 sitesname.com sitesname2.com sitesname3.com 
例如:

然后转到
XAMPP
安装位置

对我来说,它是:
E:\xampp
。然后转到其中的文件夹
apache\conf\extra
。查找名为
httpd vhosts.conf
E:\xampp\apache\conf\extra\httpd vhosts.conf

然后加上

<VirtualHost *>
    DocumentRoot "E:\xampp\htdocs\Sites\site1"
    ServerName sitesname.com
<Directory "E:\xampp\htdocs">
    Order allow,deny
    Allow from all
</Directory>

DocumentRoot“E:\xampp\htdocs\Sites\site1”
服务器名sitesname.com
命令允许,拒绝
通融


DocumentRoot“E:\xampp\htdocs\Sites\site2”
服务器名站点sname2.com
命令允许,拒绝
通融

例如:

保存文件并重新启动Apache服务器,然后检查sitesname.com

它对我有用


注意:有时,Apache无法访问添加在
E:\xampp\htdocs\
外部的文件夹

我相信我以前做过这件事。将应用程序系统文件夹从公用html文件夹中移动是一种最佳做法。它将阻止公众直接访问这两个文件夹。移动文件夹后,必须在public\u html\index.php文件中进行更改。将系统和应用程序路径指向上一级。请参考下面的图片查看我是如何编辑的

执行上述编辑后,现在应用程序可以正常工作,但必须在URI中包含index.php段。例如:-localhost/index.php/welcome。要消除这种情况,您必须在public\u html文件夹中创建一个.htaccess文件。请参考下图

现在为方便起见,我附上下面的重写代码

<IfModule mod_rewrite.c>

Options +FollowSymLinks
RewriteEngine on

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

</IfModule> 
将以下内容粘贴到文件中并进行必要的更改

<VirtualHost *:80>
    ServerName yoursite.dev
    ServerAlias *.yoursite.dev
    DocumentRoot /path/to/public_html/folder

<Directory />
    #Options FollowSymLinks
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Require all granted
</Directory>

</VirtualHost>
编辑主机文件以解析yoursite.dev文件

sudo nano -w /etc/hosts
在末尾添加以下行并保存文件

127.0.0.1       yoursite.dev
如果您跟着我,现在您可以使用以下URL访问您的开发站点:yoursite.dev/index.php

sudo nano -w /etc/hosts

我希望这将帮助你,如果你有任何疑问,请让我知道

您可以在C:\Windows\System32\drivers\etc\处看到主机文件

使用编辑器,您必须添加以下代码:

127.0.0.1  local.site1.com
127.0.0.1  local.site2.com
之后,您必须在C:\xampp\apache\conf\extra\httpd-vhosts.conf中添加此文件

<VirtualHost *>
    DocumentRoot "C:\xampp\htdocs\Sites\site1"
    ServerName local.site1.com
</VirtualHost>
<VirtualHost *>
    DocumentRoot "C:\xampp\htdocs\Sites\site1"
    ServerName local.site2.com
</VirtualHost>
完成

  • 在apache中设置一个连接到本地文件夹的虚拟主机(my.local.dev)
  • 通过将操作系统添加到主机文件,诱使其使用
  • (重新启动apache)
  • 还是失败?公共html中的htaccess或更改codeigniter路由

您为什么想要这个?我也不认为这是可能的。这可能只是可行的,但这取决于你需要它做什么。一些想法包括定制浏览器代码、本地主机服务器代码以及我不知道如何做的事情。最好的方法是使用和或来设置它,让您了解如何使用多个应用程序示例您是否尝试过编写rewr
127.0.0.1  local.site1.com
127.0.0.1  local.site2.com
<VirtualHost *>
    DocumentRoot "C:\xampp\htdocs\Sites\site1"
    ServerName local.site1.com
</VirtualHost>
<VirtualHost *>
    DocumentRoot "C:\xampp\htdocs\Sites\site1"
    ServerName local.site2.com
</VirtualHost>
RewriteEngine on
RewriteBase /site1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

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