[wp-hackers] How to make root relative urls work in, subdomain

Marcus Pope Marcus.Pope at springbox.com
Mon Oct 31 16:28:44 UTC 2011


Hey Ryann, unfortunately I got sucked into a 6 hour meeting in the next 10 minutes so I won't be able to write up a response as complete I would like.  But I can fill you in on more details tomorrow if you don't figure out an option from this response.

Basically you are 90% of the way there.  I'm not sure if the email thread removed the newline, but you'll want to put the RewriteRule on its own line underneath the RewriteCond statement.  You can also take out http://wp.dev and just use /testproject/$1.  And additionally you will want to put [R=301,L]  which indicates that the redirect is a permanent move (301) and to stop processing anymore rules L == Last Rule.

Otherwise the rest looks good.  If the above suggestions don't work out let me know and I'll spend a little more time looking at it.  Here's a formatted version for you to view.. 

RewriteEngine on

#be sure to include the wordpress .htaccess rules here

#and put this at the bottom of your file
RewriteCond %{REQUEST_URI} !^/testproject/ 
RewriteRule ^wp\.dev/(.*) /testproject/$1 [R=301,L]

#end of file

Thanks!
-Marcus
-----Original Message-----
From: wp-hackers-bounces at lists.automattic.com [mailto:wp-hackers-bounces at lists.automattic.com] On Behalf Of Ryann Micua
Sent: Monday, October 31, 2011 3:11 AM
To: wp-hackers at lists.automattic.com
Subject: Re: [wp-hackers] How to make root relative urls work in, subdomain

Hi Marcus, thank you for replying. I'm interested in the .htaccess rewrite rule. How do I write it? I tried the following:

RewriteEngine on
RewriteCond %{REQUEST_URI} !^/testproject/ RewriteRule ^wp\.dev/(.*) http://wp.dev/testproject/$1

references:
http://stackoverflow.com/questions/2982205/using-htaccess-rewrite-to-make-a-subdirectory-be-its-own-root-for-root-relative
http://stackoverflow.com/questions/4844069/htaccess-rewritebase

I'm fine with just the .htaccess solution

I don't know mod_rewrite very well although I'm getting the hang of writing simple regex patterns.

Thanks so much!

On Monday, 31 October, 2011 01:33 PM,
wp-hackers-request at lists.automattic.com wrote:
> Hey Ryann, I would suggest that you always use /css/base.css. Then on your dev and staging site I would use an .htaccess rewrite rule that checks for the project name at the start of the request_uri. If it's not there rewrite the url with it prepended at the start. Since .htaccess files have access to environment variables you could even make it controlled by code in the wp_config.php file so you wouldn't have to create a new custom .htaccess file for every project.
>
> Alternatively you could add a custom rewrite rule in wordpress itself. The wordpress rewrite apihttp://codex.wordpress.org/Rewrite_API  is fully capable of handling this scenario as well, though performance would be faster in mod_rewrite (.htaccess). This api is how wordpress maps urls like /year/month/day to the correct file, as you probably already know there is no actual file for such a url. Considering this is the premise for 90% of the urls processed by the core it is still suitable for your situation. And for dev environments the performance loss is probably not noticeable.
>
> That way when you switch to production everything will work without the specialized rules and you will have zero performance loss along with zero refactoring costs.
>
> Hope that helps, if you have questions about specifics just ask!

--
*Ryann Micua*
/Web Developer/
------------------------------------------------------------------------

Website: /www.pogidude.com/
Skype: /rmicua/
Mobile: /+639169273059/

_______________________________________________
wp-hackers mailing list
wp-hackers at lists.automattic.com
http://lists.automattic.com/mailman/listinfo/wp-hackers


More information about the wp-hackers mailing list