I am keen to understand how I might be able to do the following.

A list of products or things that might be a JSON data object or flat text file of things.

Let's say the list of things is:


I want to get a URL system that does this:


where twitter or facebook is the variable and I want domain.com/advice-on-<random string> to 404.

So I am seeing how to make a slug cause a template to load according to the template but I don't want to create a whole page in the backend with a slug.

So I want to make a dynamic page creation idea. The variable will be used with php to build content that is unique and render that per page.

I don't think there is much that can be done with .htaccess for this problem.

I want to get the string from the URL in PHP and therefore build my content.

I just need to get a page-template PHP file to load where I can start my PHP work.

Hope this makes sense.

Thank you for any pointers as it is a loaded question to a degree.

1 Answer 1


I would actually tackle it with the .htaccess file, using RewriteCond and RewriteRule, something like:

RewriteCond %{REQUEST_URI} ^/advice-on-(\[a-zA-z])$
RewriteRule ^/?(.*) http://domain.com/customadvice?advice=$1 [L]

Note that the Regex in the parenthesis will be reused as $1 in the RewriteRule.

You should then have a WordPress page on /customadvice and use the $_GET attribute from the page template for whatever use you need.

The path /advice-on should still give a 404.

  • Oh this could work, I will get testing thank you. My issue for not using htaccess was that it couldn't query my list of 'things' but I can do this check later and 404 if the url stripped doesn't match them...TY Marc-Antoine.
    – landed
    Jan 13, 2017 at 11:37
  • I am struggling to get a match for RewriteCond %{REQUEST_URI} ^/advice-on-([a-zA-z])$ will continue to see why....
    – landed
    Jan 13, 2017 at 14:10
  • RewriteCond %{REQUEST_URI} ^/advice-on-[a-zA-Z]*$ [NC]
    – landed
    Jan 13, 2017 at 17:02
  • Ok So I can now get the variable in my page but creating a new page has changed the url.. I need the url to be domain.com/advice-on-twitter vs domain/customadvice/advice-on-twitter and the issue is the redirect keeps recursing...because it matches always "advice-on-"
    – landed
    Jan 13, 2017 at 17:35
  • 1
    "My issue for not using htaccess was that it couldn't query my list of 'things'" - if you have access to the server config, you can use a RewriteMap. It would be more efficient to match the URL in the RewriteRule pattern. No need for the RewriteCond in this instance.
    – MrWhite
    Jan 14, 2017 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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