在 CentOS 系统中,配置 Apache 伪静态 URL 需要修改 Apache 的配置文件。以下是一个基本的步骤指南:
sudo yum install httpd
sudo systemctl start httpd
sudo systemctl enable httpd
/etc/httpd/conf/httpd.conf。你也可以使用 vi、nano 或其他文本编辑器:sudo vi /etc/httpd/conf/httpd.conf
<Directory> 部分,它定义了 Apache 服务器的根目录和其他目录的访问权限。在这个部分中,确保允许使用 .htaccess 文件进行重写规则。例如:<Directory "/var/www/html">
AllowOverride All
</Directory>
保存并关闭配置文件。
创建或编辑 .htaccess 文件。这个文件通常位于你的网站根目录下,例如 /var/www/html。如果该文件不存在,请创建一个:
sudo vi /var/www/html/.htaccess
.htaccess 文件中添加你的伪静态 URL 规则。以下是一个简单的示例,将所有请求重写到 index.php 文件:RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
保存并关闭 .htaccess 文件。
重新加载 Apache 服务以应用更改:
sudo systemctl reload httpd
现在,你的 CentOS Apache 服务器应该已经配置好了伪静态 URL。请根据你的实际需求调整重写规则。