首页 > 解决方案 > HTACCESS 上的自定义重写

问题描述

我的网站上已经有一个 htaccess 文件,它可以完成以下工作。例如,它将example.com/steve转换为example.com/profile.php?id=steve

这意味着像example.com/something这样的 url应该去配置文件。

现在,我在从网站的其他 url 中删除 .php 扩展名时遇到了问题。

例如example.com/home应该打开主页,但它认为这是一个名为“home”的配置文件。

我们怎么能两者兼得?

我的 htaccess 文件

RewriteEngine on

RewriteCond %{REQUEST_METHOD} !^POST$

# Forcing HTTPS
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{SERVER_PORT} 80

RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^ https://example.com%{REQUEST_URI} [R=302,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/\.]+)/?$ profile.php?id=$1 [L]
RewriteRule ^([^/\.]+)/([^/\.]+)/?$ profile.php?id=$1&amount=$2 [L]

标签: apache.htaccess

解决方案


推荐阅读