Support » Fixing WordPress » mod_rewrite breaking everything except WP!

  • Ok, so I upgraded to WP1.5 at and everything looked peachy until I tried to install Vanilla forum.

    Because of the mod_rewrite used by WP, everything seems to be processed which breaks any non-absolute URLs.

    For example, would 301 (Permanently moved) because mod-rewrite would try and fiddle with it.

    My blog is installed in the top level of my website, and I believe this might be the problem ?

    /posts/%post_id% is the formatting I’m applying to the permalinks in the options page, they have been rebuilt since I upgraded and I don’t hav a category prefix.

    is there any way to prevent WP rewriting everything, and to just re-write WP specific keywords, or am I dooomed and must I move my blog into a /blog/ subfolder?

    How difficult is it to move an established blog into a subfolder to mitigate these issues?

    Many thanks in advance,

Viewing 10 replies - 1 through 10 (of 10 total)
  • skippy



    You can leave your blog in the root of your site, and place your forum in a sub-directory. Apache should recognize that the requested URL is a valid directory inside the web space, and not attempt to rewrite the URLs.

    You can navigate to sub-directories inside your WordPress installation, for example:
    The page is blank, but that’s by design. Compare that to an attempt to load
    where your “no directory browsing” rule will kick in.

    The forum is in a subdirectory and that’s the problem… The mod_rewrite seems to be hassling relative links, used in lots of web apps out there.

    For example, when the .htaccess that wordpress created is left in place, a link to “/vanilla” will 301. Without the .htaccess that wordpress creates, it’s all fine and dandy.

    At best the problem seems intermittent, which is even more weird. For example when trying to log into my forum, 2/3 times it 301’s and ocassionally it lets me through. Very, very odd.




    I get a 404 at — is that where you are trying to place your forum?

    the forum is at sorry, was using an example earlier.

    Trailling slash and it works, no trailling slash and it breaks… That’s why links in automated emails are failling, as they don’t have trailling slashes. At least I’m nearer to a conclusion.

    With that known, any offers as to how to approach a fix? Many thanks for your fast replies!




    You can add a custom rule at the top of your .htaccess file, before the WordPress block of rules, that looks something like this:
    RewriteRule ^vforum$ /vforum/ [QSA,L]

    That should catch the URL without a trailing slash, and rewrite it to use the trailing slash.

    Surely then I would have to write a mod-rewrite for every explicit subfolder on my site? That wouldn’t be particularly desirable, it would be better to handle things “normally” but I don’t know if that’s possible.

    I’m having an issue with this as well – with the mod rewrite rules I cannot access most subfolders on my site, unless I’m referencing a specific file in that path. I keep my blog in the root of the site, so pretty much everything falls below it. Any ideas on fixes from the WP team or users is appreciated!

    Right. Cracked it with a bit of help from IRC. This is *NOT* a nice clean fix, it’s computationally heavy (So I’m told) so I would greatly appreciate someone coming in with a better solution.


    At the top of the standard wordpress .htaccess file you should see the following:

    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ – [S=45]

    What this is saying is (To my limited understanding) if the requested URL is a valid file or directory, do nothing and skip the next 45 rules.

    However, directories without trailling slashes don’t seem to get the correct treatment. mod_dir or something in apache is supposed to re-write directories with a trailling slash by default but at least on my server this wasn’t hapenning.

    So, I modified the .htaccess file to read as follows:

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^(.+[^/])$ $1/ [R,L]
    RewriteCond %{REQUEST_FILENAME} -f [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [S=45]

    As you can see, I only had to add lines 3 and 4. What they say is if the requested URL is a valid directory, rewrite it with a trailling slash and stop right there. So far WordPress permalinks appear to be working, but Im told this way of doing things is a little process intensive on the server.

    If anyone can come up with a better way of doing it I’m all ears. Hope this helps in the meantime though!

    I don’t know if it’ll help you, but there was some plugin that basically fixed that trailing / no trailing slash thing for WP links… and of course I can’t find it right now, so I’m basically a wealth of no knowledge.

    You could add this rule outside the WP block:

    RewriteCond %{REQUEST_FILENAME}/ -d
    RewriteRule ^(.*)$ $1/ [L,R=301]

    You could also try the N flag instead of R, since you only need to *internally* resolve the request as a folder, and you may want to further rewrite requests to that folder (depending on what folder it is.) R will send a 301 or 302 header, and the browser will actually make another request.

    Check out the mod_rewrite documentation for more information.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘mod_rewrite breaking everything except WP!’ is closed to new replies.