大网数据广告活动
网站运营与故障问答

Is there an alternative to .htaccess?

· 52CE 我爱测

Is there an alternative to .htaccess , in case the webhoster disabled the use of .htaccess files? I can set some PHP variables and headers inside the PHP files but how can I perform actions like mod_rewrite rules and default 404 …

问题原文

原帖链接 · Bob Ortiz · CC BY-SA 3.0

Is there an alternative to .htaccess, in case the webhoster disabled the use of .htaccess files?

I can set some PHP variables and headers inside the PHP files but how can I perform actions like mod_rewrite rules and default 404 pages?

已采纳解答

原帖链接 · MrWhite · CC BY-SA 4.0

...in case the webhoster disabled the use of .htaccess files?

If the webhost has disabled the use of .htaccess files then there is no direct alternative. (.htaccess = per-directory Apache config file)

.htaccess files are not necessary if you have access to the Apache server config. In fact, it is preferable to use the server config instead of .htaccess anyway, but by the sounds of it, you do not have that luxury.

I can set some PHP variables and headers inside the PHP files

With PHP 5.3+ under CGI/FastCGI then you can use .user.ini files for per-directory PHP config settings. But that's just for PHP config settings, eg. error_reporting, include_path, etc. (Mind you, under CGI/FastCGI you need to use .user.ini, since you'll get a 500 internal server error if you try to use php_flag and php_value directives in .htaccess - these are for when PHP is installed as an Apache module.)

If your (shared) host has disabled .htaccess and you are wanting to do more that serve simple files then... find a new host.

Just to add, it's possible for the webhost to change the name used for per-directory Apache config files (ie. ".htaccess files") using the AccessFileName directive in the server config. However, I have never encountered a host that has done this and it might possibly break other software if it is changed. It is universally expected that the Apache per-directory config file is called ".htaccess".

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2016-06-22)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0 / CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。