我的目标是不再需要拥有 .htaccess 文件的本地副本和实时副本,而是能够对本地/实时配置使用相同的单个 .htaccess 文件。这将迫使我更好地理解配置服务器。
我的本地服务器是我计算机上的 XAMPP,而我的实时服务器是共享 Web 主机,我显然无法更改设置。我还没有达到可以从头开始配置所有内容的程度,因此我将继续使用 XAMPP 一段时间。此外,任何熟悉 XAMPP 的人都应该知道,我尝试使用他们的论坛(登录/密码重置失败),而管理员已经好几天没有回复我的电子邮件了,所以我确实尝试了更符合目标的路线,但没有成功。
更具体的问题是我想将我的实时共享服务器的 PHP 处理程序用于我的本地服务器。
要在我的实时共享网络主机上的非本机文件中执行 PHP,我使用以下命令...
public_html/.htaccess
AddType application/x-httpd-php5 .css .html .js .txt .xml
...我想配置我的计算机/本地设置来模拟它,所以我不这样做不必为本地/实时保留 .htaccess 文件的单独副本(这迫使我学习如何配置服务器)。目前我必须在本地使用以下内容...
public_html/.htaccess
AddType application/x-httpd-php .css .html .js .txt .xml
我能够追踪配置似乎在 XAMPP 1.7.7(当前最新版本)中的位置...
xampp\apache\conf\extra\httpd-xampp.conf
现在我对更改正在使用的 PHP 版本不感兴趣(不是我的目标)...我只是想确保我可以使用本地的手柄和我住的一样。我尝试简单地将字符串“5”添加到下面的第 17 行(?),尽管这不起作用(保存,停止服务器,当然重新启动服务器)。
<IfModule env_module>
SetEnv MIBDIRS "C:/MEDIA/INTERNET/xampp/php/extras/mibs"
SetEnv MYSQL_HOME "\\xampp\\mysql\\bin"
SetEnv OPENSSL_CONF "C:/MEDIA/INTERNET/xampp/apache/bin/openssl.cnf"
SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php"
SetEnv PHPRC "\\xampp\\php"
SetEnv TMP "\\xampp\\tmp"
</IfModule>
#
# PHP-Module setup
#
LoadFile "C:/MEDIA/INTERNET/xampp/php/php5ts.dll"
LoadModule php5_module "C:/MEDIA/INTERNET/xampp/php/php5apache2_2.dll"
<FilesMatch "\.php$">enter code here
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
#
# PHP-CGI setup
#
#<FilesMatch "\.php$">
# SetHandler application/x-httpd-php-cgi
#</FilesMatch>
#<IfModule actions_module>
# Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
#</IfModule>
<IfModule php5_module>
PHPINIDir "C:/MEDIA/INTERNET/xampp/php"
</IfModule>
<IfModule mime_module>
AddType text/html .php .phps
</IfModule>
ScriptAlias /php-cgi/ "C:/MEDIA/INTERNET/xampp/php/"
<Directory "C:/MEDIA/INTERNET/xampp/php">
AllowOverride None
Options None
Order deny,allow
Deny from all
<Files "php-cgi.exe">
Allow from all
</Files>
</Directory>
<Directory "C:/MEDIA/INTERNET/xampp/cgi-bin">
<FilesMatch "\.php$">
SetHandler cgi-script
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler None
</FilesMatch>
</Directory>
<Directory "C:/MEDIA/INTERNET/xampp/htdocs/xampp">
<IfModule php5_module>
<Files "status.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
<IfModule alias_module>
Alias /security "C:/MEDIA/INTERNET/xampp/security/htdocs/"
<Directory "C:/MEDIA/INTERNET/xampp/security/htdocs">
<IfModule php5_module>
<Files "xamppsecurity.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
Alias /phpmyadmin "C:/MEDIA/INTERNET/xampp/phpMyAdmin/"
<Directory "C:/MEDIA/INTERNET/xampp/phpMyAdmin">
AllowOverride AuthConfig
</Directory>
Alias /webalizer "C:/MEDIA/INTERNET/xampp/webalizer/"
<Directory "C:/MEDIA/INTERNET/xampp/webalizer">
<IfModule php5_module>
<Files "webalizer.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
</IfModule>
所以我不知道如何分配“application/x-httpd-php5”来与分配给“application/x-httpd-php”的任何内容一起使用并记住我不想更改我正在使用的 PHP 版本(工作正常)。
我还应该注意到,使用该程序 Advanced Find &将我在 XAMPP 目录中找到的总共 8 个文件替换为字符串“application/x-httpd-php”,但上面的文件是唯一一个似乎与 Apache 配置相关的文件。
My goal is to stop having to have a local copy and a live copy of my .htaccess file and instead be able to use the same single .htaccess file for BOTH local/live configurations. This will force me to better understand configuring a server.
My local server is XAMPP on my computer while my live server is a shared web host where I obviously can't change settings. I'm not at the point where I can configure everything from scratch so I'll be sticking with XAMPP for a while longer. Additionally anyone familiar with XAMPP should know that I attempted to use their forums (broken signin/password reset) and the admin hasn't responded to my email for days so I did try the more on-target route without success.
The more specific issue is I want to use my live shared server's PHP handler for my local server.
To execute PHP in non-native files on my live shared web host I use the following...
public_html/.htaccess
AddType application/x-httpd-php5 .css .html .js .txt .xml
...I want to configure my computer/local setup to emulate this so I don't have to keep separate copies of .htaccess files for local/live (this forces me to learn how to configure the server). Currently I have to use the following locally...
public_html/.htaccess
AddType application/x-httpd-php .css .html .js .txt .xml
I was able to track down where the configuration seems to be in XAMPP 1.7.7 (current latest release)...
xampp\apache\conf\extra\httpd-xampp.conf
Now I'm not interested in changing the PHP version that's being used (not my goal)...I just want to make sure that I can use the same handle locally as I do live. I tried to simply add the string '5' to line 17(?) below though that didn't work (saved, stopped server, restarted server of course).
<IfModule env_module>
SetEnv MIBDIRS "C:/MEDIA/INTERNET/xampp/php/extras/mibs"
SetEnv MYSQL_HOME "\\xampp\\mysql\\bin"
SetEnv OPENSSL_CONF "C:/MEDIA/INTERNET/xampp/apache/bin/openssl.cnf"
SetEnv PHP_PEAR_SYSCONF_DIR "\\xampp\\php"
SetEnv PHPRC "\\xampp\\php"
SetEnv TMP "\\xampp\\tmp"
</IfModule>
#
# PHP-Module setup
#
LoadFile "C:/MEDIA/INTERNET/xampp/php/php5ts.dll"
LoadModule php5_module "C:/MEDIA/INTERNET/xampp/php/php5apache2_2.dll"
<FilesMatch "\.php$">enter code here
SetHandler application/x-httpd-php
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler application/x-httpd-php-source
</FilesMatch>
#
# PHP-CGI setup
#
#<FilesMatch "\.php$">
# SetHandler application/x-httpd-php-cgi
#</FilesMatch>
#<IfModule actions_module>
# Action application/x-httpd-php-cgi "/php-cgi/php-cgi.exe"
#</IfModule>
<IfModule php5_module>
PHPINIDir "C:/MEDIA/INTERNET/xampp/php"
</IfModule>
<IfModule mime_module>
AddType text/html .php .phps
</IfModule>
ScriptAlias /php-cgi/ "C:/MEDIA/INTERNET/xampp/php/"
<Directory "C:/MEDIA/INTERNET/xampp/php">
AllowOverride None
Options None
Order deny,allow
Deny from all
<Files "php-cgi.exe">
Allow from all
</Files>
</Directory>
<Directory "C:/MEDIA/INTERNET/xampp/cgi-bin">
<FilesMatch "\.php$">
SetHandler cgi-script
</FilesMatch>
<FilesMatch "\.phps$">
SetHandler None
</FilesMatch>
</Directory>
<Directory "C:/MEDIA/INTERNET/xampp/htdocs/xampp">
<IfModule php5_module>
<Files "status.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
<IfModule alias_module>
Alias /security "C:/MEDIA/INTERNET/xampp/security/htdocs/"
<Directory "C:/MEDIA/INTERNET/xampp/security/htdocs">
<IfModule php5_module>
<Files "xamppsecurity.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
Alias /phpmyadmin "C:/MEDIA/INTERNET/xampp/phpMyAdmin/"
<Directory "C:/MEDIA/INTERNET/xampp/phpMyAdmin">
AllowOverride AuthConfig
</Directory>
Alias /webalizer "C:/MEDIA/INTERNET/xampp/webalizer/"
<Directory "C:/MEDIA/INTERNET/xampp/webalizer">
<IfModule php5_module>
<Files "webalizer.php">
php_admin_flag safe_mode off
</Files>
</IfModule>
AllowOverride AuthConfig
</Directory>
</IfModule>
So I don't know how to assign "application/x-httpd-php5" to work with whatever "application/x-httpd-php" is assigned to and remember I do not want to change the version of PHP I'm using (works fine).
I should also note that after using the program Advanced Find & Replace that I've found eight total files in the XAMPP directory with the string "application/x-httpd-php" however the file above is the only one that seems relevant to Apache's configuration.
发布评论
评论(1)
并不是你问题的真正答案,但我不会对自己这样做。 Apache 的配置文件格式并不是真正为此类内容构建的。
对我来说,有两个单独的 htaccess 文件(如
.htaccess
和.htaccess.local
),并通过AccessFileName
指令:是最好的方法。
如果你真的想拥有一切在一个文件中,可以通过使用
块要分离本地指令和实时指令,您必须在本地启动服务器时设置一个定义,然后可以测试该定义是否存在。Not really an answer to your question, but I wouldn't do this to myself. Apache's config file format isn't really built for stuff like this.
To me, having two separate htaccess files (like
.htaccess
and.htaccess.local
, and controlling the local server through theAccessFileName
directive:is the best way to go.
If you really want to have everything in one file, it may be possible by using
<IfDefine>
blocks to separate local and live directives. You would have to set a define when starting your server locally, and could then test for the presence or non-presence of that define.