Community Forums › Forums › Archived Forums › General Discussion › WordPress .htaccess rewrite for custom template
Tagged: htaccess mod_rewrite
- This topic has 6 replies, 3 voices, and was last updated 9 years, 6 months ago by
aristo.
-
AuthorPosts
-
May 14, 2014 at 12:14 pm #105138
aristo
MemberI 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 #105206Brad Dalton
ParticipantI'd ask this question on the Stackechange as you'll get more technical advice there. http://wordpress.stackexchange.com/questions
May 14, 2014 at 9:28 pm #105214aristo
MemberI 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 #105218Brad Dalton
ParticipantThis is where i would post your question http://stackoverflow.com/questions/tagged/.htaccess
May 14, 2014 at 10:56 pm #105222aristo
MemberI 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 #105223Summer
MemberThe 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 DarkMay 16, 2014 at 2:54 pm #105545aristo
MemberI finally got the exact answer that I was looking for. The answer can be found at WordPress Development
Thank you everyone for their help.
-
AuthorPosts
- The forum ‘General Discussion’ is closed to new topics and replies.