mod_rewrite subdomain in Symfony2 - mod-rewrite

Please help with mod_rewrite subdomain to some Symfony2 routing. It is like 3 months now I spent time to solve this with my Symfony2 project but after reading tons of apache mod_rewrite and mod_alias documentation and trying hundreds of examples... it still doesn't work!
What I try to solve is, when user enter address of some specific subdomain:
XXXXXXX.example.com
He sees content that is actually under
www.domain.com/tag/XXXXXXX/
but he is not redirected or URL isn't changed -- it should just stay XXXXXX.example.com as he enters.
I need to resolve this with Apache VirtualHost and sites-enabled file (not with SubdomainListener) but the most I can solve on my own with mod_rewrite is having
XXXXXXX.example.com
Rewriting (transparently) itself to
XXXXXXXX.example.com/tag/XXXXXXXX or
XXXXXXXX.example.com/app.php/tag/XXXXXXXX/
which of course is not what I try to achieve. I try to achieve internal (http://httpd.apache.org/docs/2.2/rewrite/remapping.html) redirection so user don't see that. Any help with working soultions would be otherworldly appreciated.

Since this commit, you can use subdomains in Symfony natively, but unfortunately it's a Symfony 2.2 feature. If you need subdomains, this still is the best way to do this, however.

Related

Redirect all requests from xyz.herokuapp.com to new provider

I have moved a website from heroku to another provider. Lets say its custom domain is www.mysite.org. It was also at mysite.herokuapp.com, although we never really used that domain, Google has indexed some pages there. I want to redirect any requests mysite.herokuapp.com/[EVERYTHING] to www.mysite.org/[EVERYTHING]. The paths are otherwise compatible. I am told Heroku does not allow you to use an .htaccess file. I've deleted the mysite project on Heroku but could create a new one thats a simple php page or something else?
I'm sure this has been asked before, i've looked but find either too little or too much information and none seems to answer my question. Thanks.

Can I create a 301 redirect from www.xcompany.com to shop.xcompany.com?

I work for xcompany. I am wondering if it is possible to set up a 301 redirect from our site http://shop.xcompany.com/ to our site http://www.xcompany.com/ and if possible, what would the rewrite rules be?
The old page that existed on the former URL has been removed from the site and a similar page has been created on the latter URL and we need to make sure any traffic is directed to the new page.
Thanks!!
RewriteRule ^old/URL/path$ http://example.com/new/path [R=301,L]
To redirect from oldsite.com to newsite.com you can use the following redirect in /oldsite/.htaccess
Redirect 301 / http://newsite.com/
Redirecting one domain to another domain is very much easier than before only if you are well familiar with CMSs like WordPress. There are plenty of redirect plug-ins available in WordPress that make our efforts easier and quicker.
301 redirection must be done if you have made any changes to the older URL and it will give link juices without losing its ranking, backlinks, and all others.
You need not worry about anything. Redirect your older one to new one. Then Google webmaster tool will give a report if your new site causes crawling errors. Hope it'd be helpful.

Apache2 mixing mod_vhosts_alias and mod_rewrite

The Apache2 docs recommend mod_rewrite as a last resort for specifying which directory to send a given host request to. They said use mod_vhosts_alias. I set that up and its working without problem. However, I have a specific case that entails some mod_rewriting.
I have a domain like mydomain.com and a large number of subnames like sub.mydomain.com and sub2.mydomain.com. These subdomains all map to corresponding directories. But the subdomains will also have full top-level domains that map to respective directories. For instance:
sub.mydomain.com will map to the same directory as awesomeproducts.com sub2.mydomain.com will map to the same directory as widgets.com
What would be the best way to make sure both these methods of accessing each site will work without conflict?
Since the docs only say mod_rewrite isn't as "graceful" as mod_vhosts_alias, I didn't know if I ought to use mod_rewrite completely by itself for my situation or if I should be trying to mix the two approaches somehow.
Is mixing them the way to go or will that create problems?
The behaviors of RewriteRule and RewriteCond change when using mod_vhost_alias. Its been a few days since I tinkered with it so I'm sketchy on it, but watch out for the way RewriteRule interprets the portion of the URL to be rewritten. It may change when using mod_vhost_alias... and RewriteCond behavior might change too.
To accomplish the question I was asking about, I ended up using symbolic links for the actual domains. I setup a bunch of subdomains with associated folders so that sub1.stddomain.com would go to the folder sub1.stdomain.com. Then I added a symbolic link that maps domain1.com to the sub1.stddomain.com folder. That way anyone who visits domain1.com is shown the site in the sub1.stddomain.com folder.
IMPORTANT: After all that work and testing, I ended up going back to to a collection of virtualhost files WITHOUT mod_vhost_alias. Turns out that there is a known problem with mod_vhost_alias. DocumentRoot isn't correctly set when using it. This breaks tons of scripts. It was patched in February 2012 with new special variables and the programming team at Apache dropped the ball. They never wrote any documentation explaining how to use the patch or new variables.
I reopened the issue and stated that its still a bug since you can't write code and not tell anyone how to use it and then call it fixed. Unfortunately the issue had already been ignored for YEARS and it will probably continue to get ignored even though they supposedly wrote code for it.
RECOMMENDED LESSON FROM ALL THIS: Don't use mod_vhost_alias. Write shell scripts to manage your vhost files using one more template files.

discover if mod_rewrite is working (MAMP + codeigniter)

I'm experimenting (and having problems!) with codeigniter.
In particular, links do not work.
even if they are correct (eg. http://localhost/ci-book/welcome/cat/3, where welcome is controller, cat the method), they can't be open and chrome says "Oops! This link appears to be broken...."
Someone suggested to check that mod_rewrite is working. How can I do that?
I'm using Mamp.
thanks,
P.
First, check that the basic URL without mod_rewrite works: http://localhost/ci-book/index.php?welcome/cat/3
Then setup mod_rewrite, restart httpd, and attempt to navigate back to your URL. If it works (or at least, if part of the page loads with errors), then mod_rewrite is working.

How can I test if IIRF works?

http://www.codeplex.com/IIRF/Thread/List.aspx
My webhost installed IIRF for me and I am convinced that they did not do it correctly. I've tried numerous examples including one that I know works with apache's mod_rewrite but I can't get anything to work with IIRF. Is there rule or configuration option that you guys have that you know of that will show whether or not the thing is working correctly?
Even something like rewrite all urls to anothersite.com will will help me right now. I hope you guys realize the reason I came for your help. I can figure out how to do the rewrite rules on my own but I don't know if the errors are because of me or the webhost. I have limited options as well since I am on a shared webhost.
The new version of IIRF, v1.2.16 R3, includes a StatusUrl directive that will give you a status page if you do an HTTP GET on it. It looks like this:
If you get that page, then IIRF is running.
This is tested and working with IIRF:
RedirectRule ^.*$ http://www.google.com/ [I,R=301]
It will match any URL and redirect to Google.

Resources