TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   mod_rewrite subdomain & WordPress problem (http://www.talkphp.com/general/3149-mod_rewrite-subdomain-wordpress-problem.html)

Gilles 07-20-2008 11:03 AM

mod_rewrite subdomain & WordPress problem
 
Hey everyone,

sorry for my first post being a question, but I've been trying everything and googled everything all night.

For one of my sites, annoyed.me, I want a subdomain to redirect to a folder on the main site; for example:

wordpress.annoyed.me -> annoyed.me/?tag=wordpress

I think I've done all the required work: the wildcard dns is setup and the .htaccess is pretty much complete (I think) but it's throwing me a 500 error. Would this have something to do with WordPress?

This is my .htaccess code:
Code:

<IfModule mod_rewrite.c>

        Options +FollowSymLinks
        RewriteEngine on

        # BEGIN Subdomain
        RewriteCond %{HTTP_HOST} !^www\.annoyed\.me$ [NC]
        RewriteCond %{HTTP_HOST} ^([^\.]+)\.annoyed\.me$ [NC]
        RewriteRule ^([^/]+)$ /index.php?tag=%1 [L]
        # END Subdomain

        # BEGIN WordPress
        RewriteBase /
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule . /index.php [L]
        # END WordPress

</IfModule>

If anyone could help me out? As far as I know, the mod_rewrite is working fine. I changed index.php?tag=%1 to tag/%1/ which then gave me a 404 error that it couldn't find the folder (with the correct naming etc ...)
Code:

[Sun Jul 20 11:55:51 2008] [error] [client 87.67.212.144] File does not exist: /home/annoyed/public_html/tag/redirect
Anyone have any clues on what could be giving me this 500 error? If you need any more information, just let me know.

EDIT: obviously, you can see the error here: http://prologue.annoyed.me (this is an actual tag, so if I would be able to fix this, it should show Prologue annoyed these people but, obviously, with http://prologue.annoyed.me)

Schroder 07-20-2008 03:01 PM

If I understand what you want to do correctly I think you want to replace
Code:

RewriteRule ^([^/]+)$ /index.php?tag=%1 [L]
with something like this:

Code:

RewriteRule ^([^/]+)$ http://annoyed.me/?tag=%1 [R=301,L]
I haven't been able to test this out yet, but this should at least get you on the right track.

Gilles 07-20-2008 03:18 PM

Yes, something similar... This works but the URL in the address bar is changed, something it shouldn't. When I remove the 301 redirect, it throws another 500 error.

I think it's because it conflicts with the way WordPress handles their own mod_rewrite rules...

Schroder 07-20-2008 03:32 PM

Alright. So if someone types in wordpress.annoyed.me the address stays as wordpress.annoyed.me, but internally it is annoyed.me/?tag=wordpress?

What problems were you running into with:
Code:

RewriteRule ^([^/]+)$ /index.php?tag=%1 [L]

Gilles 07-20-2008 03:59 PM

It was giving a 500 error... However, when I set it to redirect to a dir different from the WordPress install directory, it works fine.

My guess it has something to do with the WordPress .htaccess mod_rewrite rules? Is there maybe a way to combine the two different RewriteRules into a single one... Or would I have to add a exception to the WordPress .htaccess mod_rewrite rules?

Any suggestions are welcome :D

Schroder 07-20-2008 04:04 PM

Sounds like your suspicions are right. I would need to play around with the wordpress .htaccess to get a better idea what exactly is causing the issue.

What error is displaying in the log when you have it as "/index.php?tag=%1"? That may shed some light on the issue.

Gilles 07-20-2008 04:13 PM

http://prologue.annoyed.me/ - This gives you the 500 error;
Prologue annoyed these people - This is the page it should display.

It finds the page since it doesn't throw a 404 error. Appearantly, the .htaccess does something with the url which cuases it to give a 500 error.

I'm clueless tbqh.

I've tried to make them not clash, but no luck from the looks of it... My current .htaccess file:
Code:

<IfModule mod_rewrite.c>
 
        RewriteEngine on
        RewriteBase /

        # BEGIN Redirect www to non-www
        RewriteCond %{HTTP_HOST} ^www\.annoyed\.me$
        RewriteRule (.*) http://annoyed.me/$1 [R=301,L]
        # END Redirect www to non-www


        # BEGIN WordPress
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteCond %{HTTP_HOST} !^([^\.]+)\.annoyed\.me$ [NC]
        RewriteRule . /index.php
        # END WordPress


        # BEGIN Subdomain
        RewriteCond %{HTTP_HOST} ^([^\.]+)\.annoyed\.me$ [NC]
        RewriteRule ^([^/]+)$ /index.php?tag=%1 [L]
        # END Subdomain

</IfModule>

The first set of rules have just been added, to redirect What is annoying you today? to annoyed.me.

If anyone could help me out, let me know! I am willing to compensate you!

Schroder 07-20-2008 05:23 PM

The problem I can see with the .htaccess rule below is that the system is trying to accessing "/tag/redirect" instead of passing it through the wordpress system.

Code:

RewriteRule ^([^/]+)$ /tag/%1/index.php?tag=%1 [L]
I wasn't able to recreate this through a slightly modified rule (I used ^(.*)$ instead of ^([^/]+)$). ^([^/]+)$ did not work for me at all, which may be because I was testing it with a subdirectory instead of a subdomain.

If "/index.php?tag=%1" is causing a 500 error as well I'm curious what error is being recorded in the error log.

Besides that I think I'm as stumped as you are. Hopefully someone else has a solution they can post.


All times are GMT. The time now is 10:42 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0