Dec 17, 2008 - PHP, Wordpress    11 Comments

WordPress: Custom URL rewrite and reading URL values


Recently I was working for a Irish guy who has opened a wordpress blog few months ago. I did the theme for him. Recently he requested me for modifying and/or upgrading the project. One of the project requirements was URL rewriting. For example, there can a URL as follows:

But after rewrite, the URL should look like:

Well. You see I am passing the variable value in index.php file. But I needed to read the custom URL passed value through another PHP file and that is group.php. My group.php file was inside the theme folder. I am passing the group_name value in index.php file but reading from group.php file. It sounds a bit interesting. Huh?

OK. After browsing several blogs, I came up to writing a custom plugin. Thanks to and all those people sharing information.

My plugin made me a way so that I could pass a variable value in index.php file but read it from group.php file. This plugin code is available almost everywhere. Here goes my plugin:

So, what happens now when I activate this plugin? It does a simple work and that is: when it gets a link as below:

It sends the group_name variable value to group.php file which is in the theme folder. In group.php file, I can catch the variable value and use it anyway I want.

Do you want to see my group.php file too? OK. Here it goes:

This was half the way winning the battle.

But why? Because the following lines should solve my problem.

But for any unknown reason it was not working.

So, I had to take help of apache (dot)htaccess file for solving the rest of the part.

I was searching for a helpful blog link and after searching many blogs, I found a similar blog article and here it is:

In this blog, I found a similar solution and wrote my own based on this code.

Finally my (dot)htaccess file looked like this:

But I was not 100% perfect but close to the solution. The reason is my URL started looking like this:

Well. You see I was almost close to the solution. As the buyer wanted like this:

But I came up with a solution to:

I believe you can work on it and come to a solution without the extra “pages/” part in the URL. If you find such a solution, please share with me and others who will face similar problem.

Dude! That is all for now.

Thank you for reading.


  • Search for a plugin named “Pathless Category Links”. This will get rid of the “/category”. I imagine you can mod it to remove the “/pages”.

  • @ Bahamut

    Thank you for your suggestion.

    But it is too late.

  • Thanx.. I needed this plugin!

  • How will the code change if suppose instead of root index.php, I have a file named yshort.php residing in a template and I need to pass variables to this file and want to get it rewritten? Pls help in this case?

  • @ Navjot Singh

    Read this article:

    And try to use this plugin.
    Then you can see how they are passing variables using GET method

  • Still having some trouble getting this right…very frustrating…uggggggggh!!!

  • Hello,

    We are trying to figure out a way of having the option to use about.php for the about page and in general having the control to use COMPLETELY CUSTOM URLs for each post or page.

    What would be the solution to finding this ?


  • @ Alexander

    may be you can use some plugins developed for this purpose if available

  • Hi,

    I have been searching for a solution for a long time and see that there is really nothing available.

    Are you available to work with us to solve this problem?

  • Hey, that is a great article!

    I wonder if you offer individual help on WordPress/php problems?

    I want to create a rewrite rule or plugin that makes permalinks to articles look like .html files – to look like actual links to html-pages. And i want to make the links to embedded images in articles look like they come not from the single /flies directory, but from a directory for each article.

    Could you help with that and how much would you charge?


  • Hey Robert,

    Just so you know the rewrite rules have changed a little since this article was written and, actually, some functions have been deprecated.

    Not to take anything away from our fabulous developer and writer of this article but in the event that you will need this implemented please contact me at alexander(at)

    Good luck,


Got anything to say? Go ahead and leave a comment!