Posts Tagged ‘mod_rewrite’
All posts tagged mod_rewrite.
Apache’s mod_rewrite is very powerful. You can prevent hot-linking to your site’s graphics to prevent others from stealing them, redirect your from your old URL to a new URL, re-write URLs, as well as about 500 other really cool things…but today I wanted to share the syntax needed to redirect every incoming URL for a particular web site to a specific page. Why? This could come in handy when doing work on a site and you have a “Performing Updates” (in this case index.html) page. You can put the following code in your .htaccess or httpd.conf file:
# Enable rewrite engine
# Redirect internally all URLs to /index.html
RewriteRule .* index.html [L]
I had been struggling with the the next/previous links on my WordPress blog now for several months. Nothing excites me about mod_rewrite and permalinks in general. I know both are very powerful, but with power comes frustration.
My problem: All my permalinks were working correctly except for the next page/previous page links. WordPress was trying to use the URL: http://www.jappler.com/blog/page/1/ which was not working.
My setup: I am using WordPress as a CMS so my site is all in WordPress. My WordPress and blog address are the same: http://www.jappler.com (anything else produced an internal server error). I am using a custom permalink structure:
/blog/archive/%year%/%monthnum%/%day%/%postname%.php All blog posts go into the “general” category by default.
My solution: I finally did some research and figured out two things:
So, to fix the setup, do not worry about the Blog URI and WordPress URI, they both should be the same (assuming your WP files are in the root of your web site folder).
Using a WordPress page as the home page:
Create a page with a “page slug” of “home” for the page you want to be your home page. Also create a home.php template file and have the following code before the WordPress loop:
and choose the “Home” template for the “Home” page.. This will take care of using a WordPress page as the home page.
To take care of the blog at /blog/:
Create a page with a “page slug” of “blog”. Create a new template called blog.php and in it, use the following code:
and choose the “Blog” template for the “Blog” page.
[tags]WordPress, mod_rewrite, permalinks, jappler.com[/tags]
I cannot stress how amazing the Apache community has been when I have needed help. Not only do I spend a lot of time reading the great documentation on the Apache web site, I subscribe to the Apache mailing lists, and when I really need help fast, I jump on the #Apache channel using IRC (server=irc.freenode.net). So, if you ever have any questions/problems with Apache, support is only a few minutes away. (I had questions about some mod_rewrite syntax yesterday that I got instant help with yesterday via the IRC channel.) I know I promised a link today to my XOOPS project, but I still need a day or so to figure out the cacheing. I am not someone who likes to release links unless they are pretty polished, and I am not there yet.