所以我试图在 PHP 中构建一个干净的 url 系统来更改这样的 URLhttp://example.com/index.php?projects=05
to: http://example.com/projects/05
到目前为止,我已经弄清楚如何使用parse_url
映射看起来像的网址http://example.com/index.php/projects/05
但我不知道如何从 URL 中删除“index.php”。有没有办法使用 .htaccess 来删除index.php
来自 url 字符串?
我知道这是一个简单的问题,但经过广泛的谷歌搜索后,我找不到解决方案。
您需要在 Apache 中使用 mod_rewrite 来执行此操作。您需要将所有 URL 重定向到您的 index.php,然后,也许使用 parse_url,弄清楚如何处理它们。
例如:
# Turn on the rewrite engine
RewriteEngine On
# Only redirect if the request is not for index.php
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is not for an actual file
RewriteCond %{REQUEST_FILENAME} !-f
# or an actual folder
RewriteCond %{REQUEST_FILENAME} !-d
# finally, rewrite (not redirect) to index.php
RewriteRule .* index.php [L]
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)