简体   繁体   中英

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:

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:

example.com/post-name.

I want a way so that I can get user request without any need of index.php in the URL.

Thanks, any help will be highly appreciated.

The answer is .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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM