我的标题应该足以让你明白我实际上在努力做什么。我只想做一个简单的永久链接结构,如下所示:
example.com/post-name
我已经写了所有的代码来获得用户请求,我的代码是
$permalink = trim($_SERVER['PHP_SELF'], "/");.
之后,当index.php
被添加到URL中时,我成功地获得了用户请求,如下所示:
example.com/index.php/post-name.
但这并不是我想要实现的,我只想简单的URL结构如下:
example.com/post-name.
我想要一种方法,这样我就可以在不需要URL中的index.php
的情况下获得用户请求。
谢谢,如有任何帮助,我们将不胜感激。
答案是.htaccess:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?param=$1 [QSA,L]
请参阅:将所有内容重定向到index.php