[英]How to setup a permalink structure like wordpress with just postname after the domain name?
My title should be enough to make you understand that what I am actually trying to do. 我的头衔应该足以使您了解我实际上正在尝试做的事情。 I just want to make a simple permalink structure like this: 我只想制作一个简单的永久链接结构,如下所示:
example.com/post-name
I have written all the code to get user request, my code is 我已经编写了所有代码来获取用户请求,我的代码是
$permalink = trim($_SERVER['PHP_SELF'], "/");.
After that I have managed to get the user request when index.php
is added in the URL like this: 之后,当在URL中添加index.php
时,我设法获得了用户请求,如下所示:
example.com/index.php/post-name.
But this is not what I am trying to achieve, I just want to simple URL structure like this: 但这不是我想要达到的目的,我只想这样简单的URL结构:
example.com/post-name.
I want a way so that I can get user request without any need of index.php
in the URL. 我想要一种方法,这样我就可以在不需要URL中的index.php
情况下获取用户请求。
Thanks, any help will be highly appreciated. 谢谢,任何帮助将不胜感激。
The answer is .htaccess: 答案是.htaccess:
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?param=$1 [QSA,L]
See: Redirect everything to index.php 请参阅: 将所有内容重定向到index.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.