• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

WordPress .htaccess rewrite for custom template

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › WordPress .htaccess rewrite for custom template

This topic is: resolved

Tagged: htaccess mod_rewrite

  • This topic has 6 replies, 3 voices, and was last updated 12 years ago by aristo.
Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • May 14, 2014 at 12:14 pm #105138
    aristo
    Member

    I am trying to convert a website to WordPress. The URLs in use are currently in the format: http://www.domain.com/database/44/category/short-item-description.html

    To display items that are stored in the database, I have created a page template DatabaseFetch.php and have added a page to WordPress to use this template at address http://www.domain.com/database/ (this can also be access by http://www.domain.com/index.php?p=39)

    The template DatabaseFetch.php will have the PHP code to get the ID number from the URL and then use this ID number to get the relevant item details from the database.

    I am trying to alter the .htaccess file found in the WordPress root folder as I want all URLs in the format of http://www.domain.com/database/44/category/short-item-description.html to be processed by http://www.domain.com/database/ but I want the browser to display the URL in the format of http://www.domain.com/database/44/category/short-item-description.html (ie the URL not to change)

    I have tried many combinations over the last couple days but I cannot get it working. Using the line:

    RewriteRule ^/?database/([0-9]+)/?([a-zA-Z0-9_-]*)/?([a-zA-Z0-9_-]*).html$ /database/ [NC,L]

    brings up WordPress 404 page
    Using the line:

    RewriteRule ^/?database/([0-9]+)/?([a-zA-Z0-9_-]*)/?([a-zA-Z0-9_-]*).html$ /?p=39 [NC,L]

    brings up correct page, but the URL in the browser changes to http://www.domain.com/database/
    Does anyone know how I need to alter the .htaccess file below to get the desired results I seek?

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    # RewriteRule ^/?database/([0-9]+)/?([a-zA-Z0-9_-]*)/?([a-zA-Z0-9_-]*).html$  /database/ [NC,L]
    RewriteRule ^/?database/([0-9]+)/?([a-zA-Z0-9_-]*)/?([a-zA-Z0-9_-]*).html$  /?p=39 [NC,L]
    RewriteRule ^index\.php$ - [L]
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule . /index.php [L]
    
    </IfModule>
    
    # END WordPress

    I have also tried both lines with flags and no flags and combination of flags but nothing gets the desired result. On a non-Wordpress installation, I have the desired outcome defined by one line in .htaccess

    RewriteRule ^/?database/([0-9]+)/?([a-zA-Z0-9_-]*)/?([a-zA-Z0-9_-]*).html$ database.php?id=$1 [NC,L]

    The problem with WordPress is that the database page I need is not the physical DatabaseFetch.php file. therefore how do I go about the rewrite? Any help will be very much appreciated.

    May 14, 2014 at 9:04 pm #105206
    Brad Dalton
    Participant

    I'd ask this question on the Stackechange as you'll get more technical advice there. http://wordpress.stackexchange.com/questions


    Tutorials for StudioPress Themes.

    May 14, 2014 at 9:28 pm #105214
    aristo
    Member

    I have done so, but unfortunately I haven't received an answer. I thought I'd try my luck here. Seems strange that I cannot get an answer. I thought this would be quite a straight forward question for some WordPress experts that have had experience in modifying their .htaccess file.

    May 14, 2014 at 10:17 pm #105218
    Brad Dalton
    Participant

    This is where i would post your question http://stackoverflow.com/questions/tagged/.htaccess


    Tutorials for StudioPress Themes.

    May 14, 2014 at 10:56 pm #105222
    aristo
    Member

    I have my question posted at http://stackoverflow.com/questions/23624438/wordpress-htaccess-rewrite-for-database-template

    It is already tagged with .htaccess but it is not on the link you sent as it is not featured (ie no bounty attached to the question). Unfortunately my low reputation score restricts me from offering a bounty for this question. I wish you could purchase bounty points. I actually paid to get an answer on WP Questions

    The guy tried really hard to answer my question but I think he just led me on a wild goose chase

    May 14, 2014 at 11:28 pm #105223
    Summer
    Member

    The rewrite rule you have in the first post is correct, and will give you the result of http://www.domain.com/database/ and because of the rewrite rules in effect for the WordPress permalinks.

    If you have your link settings in WP set to default, your directive to send everything to /?p=39 will work but /database will not work, since that's considered a pretty permalink.

    What are you really trying to accomplish with this set of rewrites? Are you trying to redirect all of the individual .html URLs back to /database/ or is it something else?

    What you've asked, to have the server display one URL while actually accessing another is not possible. There is no way to rewrite the URL but have it display a different URL, not without using iframes or rewriting the base code in the apache server source code.

    The directive you say works on a non-WP site isn't displaying what you've described either; it's displaying /database.php?id=X where in your example I'm guessing the ID would be 44. So you're not sending everything to just /database/ on that site either.

    Can you provide a link to your active site, and a detailed description of what you're trying to do? What's the original site you're converting from using, something like Drupal or Joomla or something else? I think an earlier thread you started with this question had a different example link in it.

    It really sounds like you might be asking the wrong question, which could be why you're goose chasing at the moment.


    WordPress / Genesis Site Design & Troubleshooting: A Touch of Summer | @SummerWebDesign
    Slice of SciFi | Writers, After Dark

    May 16, 2014 at 2:54 pm #105545
    aristo
    Member

    I finally got the exact answer that I was looking for. The answer can be found at WordPress Development

    Thank you everyone for their help.

  • Author
    Posts
Viewing 7 posts - 1 through 7 (of 7 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble