简体   繁体   中英

How to change GET variables using .htaccess in wordpress for pretty URL

I know how to change URL in PHP but I am not an expert in WordPress.

I have this URL:

domain.com/parent-page/child-page-here/?id=SomeText

and I want this

domain.com/parent-page/child-page-here/Some Text:

I changed .htaccess but its not working here is my .htaccess code

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
RewriteEngine On
RewriteRule ^parent-page/child-page/([0-9a-zA-Z]+) parent-page/child-page/?id=$1 [NC,L]

No need to use the .htaccess as Wordpress comes with the feature you are required. All you have to do is change the permalink as here from the admin dashboard.

@mapmalith is correct, with WordPress you can simply change the permalinks in your settings.

However, if for whatever reason you're unable to do this, then you can use the following inside your .htaccess file:

RewriteEngine On
RewriteRule ^parent-page/child-page-here/([^/]*)$ /parent-page/child-page-here/?id=$1 [L]

It will leave you with the following URL: domain.com/parent-page/child-page-here/SomeText . Just make sure you clear your cache before you test this.

Obviously you will need to rename the directories to the correct names.

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