0

I added a page to my WordPress, I wanted to rewrite the url of the page to a more user friendly one .

https://localhost/wordpress/page?name=name+of+the+page

To :

https://localhost/wordpress/page/name+of+the+page

If tried to create a htaccess file in my theme directory

 function custom_rewrite_basic() {
    add_rewrite_rule('^page/([^/]*)/?', 'index.php', 'top');
 }
 add_action('init', 'custom_rewrite_basic');

I tried to redirect it to my index page to see if it works with this link :

https://localhost/wordpress/page/some+random+string

but it renders out the not found page, please help

1

You can change page URL from the page editor.

If you want to make changes for all the pages. You can go to

settings -> general settings -> permalink

and change it to your desired value.

To change for a single page, modify your .htaccess :

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^phones$ /?page_id=1081 [L]

</IfModule>
  • I want to change it for a specific page not all the website, and how to set the variables used in the link ? – user297904 Nov 27 '15 at 17:46
  • @user297904 I have changed my answer accordingly. – Sanidhay Nov 27 '15 at 18:06
  • Please I am a begginer in rewrite rule and htaccess file can you tell me exactly which patter to user when I want to match every url like this localhost/phone_numbers/france and redirect it to localhost/phone_numbers?country=france – user297904 Nov 28 '15 at 21:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.