Subdomain in Symfony gives Internal Server Error - .htaccess

I have a Symfony project (example.com) and added a subdomain (demo.example.com) pointing to the same app. The subdomain gives an Internal Server Error. The error log shows: AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary.
I set op my routing.yml like this:
account_homepage:
path: /
host: "{subdomain}.{domain}"
defaults:
_controller: AppBundle:Default:loginRedirect
requirements:
subdomain: demo|myaccount
homepage:
path: /
defaults:
_controller: AppBundle:Default:loginRedirect
Based on the Symfony docs in How to Match a Route Based on the Host.
Similar questions seem to point to the .htaccess file but I used the htaccess file shipped with Symfony:
<IfModule mod_authz_core.c>
Require all denied
</IfModule>
<IfModule !mod_authz_core.c>
Order deny,allow
Deny from all
</IfModule>
What is the way to go to get subdomains working in my project?

Changing the subdomains to Domain Pointers in DirectAdmin so subdomain.example.com becomes an alias of example.com was the solution for my project.

Related

How to show a content of one website in another website?

I have a website for example: https://test1.com, and a page on that website https://test1.com/show-content.
I want that page to display the content from another website, for example https://test2.com/show-different-content.
I know I can do it with PHP and file_get_contents, but I'm trying to do it with .htaccess, since I understand it can be possible. I've looked through all the SO questions I found regarding that, but I found no clear solution.
What I have tried in .htaccess is the following:
<IfModule mod_rewrite.c>=
RewriteEngine On
RewriteRule ^show-content$ https://test2.com/show-different-content [P]
</IfModule>
What am I doing wrong? Or am trying to do something that is not possible?
You have two options for this if the owner of that second site actually grants permission to proxy his sites content. You can use the proxy module available for the apache http server.
Either direct:
ProxyPass /show-content/ https://test2.com/show-different-content/
ProxyPassReverse /show-content/ https://test2.com/show-different-content/
Or embedded in the rewriting module:
RewriteEngine On
RewriteRule ^/?show-content/(.*)$ https://test2.com/show-different-content/$1 [P]
Obviously the proxy module needs to be loaded and activated inside the http server.

htaccess redirect htm to html (strange behaviour)

I have two hosting accounts with different providers.
both sites have the following in the htaccess.
RedirectMatch 301 ^(.*).htm $1.html
On one site (a VPS) it works as expected and
//www.example.com/page.htm
is correctly forwarded to
//www.example.com/page.html
But on the other hosting provider (shared hosting. Different provider) it removes the www from the url so goes to:-
//example.com/page.html
It only strips the www if the htm-to-html redirect occurs. So it's not all pages that have the www removed so it's not a global setting removing www from all urls.
Is that redirect syntax wrong? If so then why does it only affect the domain on one hosting provider. Or is it a setting somewhere else in the website setup?
Thanks
RedirectMatch 301 ^(.*).htm $1.html
If you don't explicitly include the hostname in the target URL (ie. specify an absolute URL) then Apache gets this information from the current server. By default, this will be the hostname used in the request (www, non-www, or whatever). However, if the directive UseCanonicalName On is set, the hostname as defined by the ServerName directive will be used. This is what I guess is happening.
Unfortunately, on a shared server, you are not going to be able to change this behaviour. The UseCanonicalName directive can only be set in the server config, not .htaccess.
I think the only resolution is to be explicit and specify the canonical hostname in the above directive:
RedirectMatch 301 ^/(.+)\.htm$ http://www.example.com/$1.html
Some people recommended to always specify an absolute target URL for redirects to avoid such problems. (Personally, I would only do this out of necessity.)

.htaccess file 404 error with parallel plesk server

I have my .htaccess file working in localhost. But its not working if i upload it in server. It throws me 404 error.
I am using Parallel Plesk 11.0.9 and i can't find conf file for the same on that. If anyone has any idea how to fix it or any workaround for url rewriting would be great help.
Anyway here's the code in htaccess:
RewriteEngine on
RewriteRule ^store/living/Hutches-Armoires-Side-tables-Coffee-tables-Entertainment-centers? store.php?store=Living
RewriteRule ^store/dining/sideboards-buffets-chairs-benches-Dining-table$ store.php?store=Dining
RewriteRule ^store/working/Bookshelves-Study-tables$ store.php?store=Working
RewriteRule ^store/accessories/Boxes-Photo-Frames-Mirror-Frames-Block-Stamps-and-Book-stands$ store.php?store=Accessories
RewriteRule ^store/hallway/Console-tables-Armoires$ store.php?store=Hallway
RewriteRule ^store/sleeping/Bed-Frames-Night-Stands-Dressers-Mirror-framesBed-Linens-Canopies-Curtains$ store.php?store=Sleeping
You may need to wrap your rewrite rules with:
<IfModule mod_rewrite.c>
...
</IfModule>
...probably a good idea anyway.
Or you could try putting your rules into a vhost.conf file in the conf directory immediately below the location of your httpdocs directory. For example on a Centos machine the web root might be
/var/www/vhosts/domain.com/httpdocs
and you should have a:
/var/www/vhosts/domain.com/conf
directory, this will contain a set of pregenerated Apache config files that Plesk creates. If there isn't already create a vhost.conf and add your rules between a set of
<Directory /var/www/vhosts/domain.com/httpdocs/ >
... your rules ...
</Directory>
Once you've created the vhost.conf file you will need to tell plesk about it with
/usr/local/psa/admin/sbin/httpdmng --reconfigure-domain domain.com
If you still can't get it to work you can add a log for mod_rewrite, see this relevant SO answer for details
Is your Plesk running IIS and supporting PHP via FastCGI or ISAPI? If that is the case, check whether URL Rewrite is installed and follow this guide to translate htaccess (for apache) into web.config (for IIS)

Protect restrict Solr Admin url from external user using .htaccess or tomcat

I have recently installed Solr on server and i want to restrict only local users can access it with .htaccess
site.com:8983/solr/admin [ restrict all user]
And below is the .htaccess code
RewirteRule on
<FilesMatch "127.0.0.1:8983/solr/admin">
Order Deny, Allow
Deny form all
Allow 127.0.0.1
</FilesMatch>
Or is there any method we can protect / restrict Solr Admin on site.com:8983/solr/admin accessing from other users
Only local ip users can use it..
And i tried this one, but its not working.
Your <FilesMatch "127.0.0.1:8983/solr/admin"> line will never match anything because you've stuck the hostname and port in the regular expression. Try using the Location container instead:
<Location "/solr/admin">
Order Deny, Allow
Deny from all
Allow 127.0.0.1
</Location>
Or better yet, Directory:
<Directory "/path/to/your/document/root/solr/admin">
Order Deny, Allow
Deny from all
Allow 127.0.0.1
</Directory>
You'll need to fill in the full path to the solr/admin directory.
Get rid of the RewirteRule on line, it doesn't do anything and it's not even spelled right and will cause a 500 error.
However, neither of these directives can be use in an htaccess file. You need to use these in either the server of vhost config. If you must use an htaccess file, then create an htaccess file in your solr/admin directory and simply put these directives in it:
Order Deny, Allow
Deny from all
Allow 127.0.0.1
Or, in the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REMOTE_ADDR} !127.0.0.1
RewriteRule ^/?solr/admin - [L,F]
Check following links. Hope they will help you.
Restrict Solr Admin Access
Solr Security
Securing Solr administrative console
How to protect Apache Solr admin console

Linking one domain to another domain with htaccess

I'm stuck with htaccess redirect on this case:
I have myapp.com domain where my main website and service runs on. My customers logs into their accounts on myapp.com and use. Now, I am going to provide one of the features on a separate domain, let's assume "goto.com". However, I don't want to build a separate app on goto.com. I just want to redirect all coming requests to goto.com to a php script under myapp.com but this redirection should be in the backend (masked), not a 301 redirection.
Let me clear up:
myapp.com - /var/www/vhosts/myapp.com/httpdocs/index.php
goto.com --> masked redirection --> myapp.com/goto.php?$1
How can I do this with htaccess? Any suggestions?
Just found that it can be done with redirect [P] (proxy) method: RewriteRule ^(.*)$ http://myapp.com/public_view/$1 [P] What do you think? Is this a good and stable method?
That method is fine, it utilizes the mod_proxy module. The only thing I can suggest is adding the L flag as well in case you have other rules in your htaccess file.
A limitation with using the P flag in an htaccess file is that if a page or request to http://myapp.com/ redirects, then you're URL address bar will say http://myapp.com/ instead of your other domain. The only way around this is to use ProxyPassReverse but it doesn't work in an htaccess file. You'd need access to vhost config:
ProxyPass / http://myapp.com/public_view/
ProxyPassReverse / http://myapp.com/public_view/
Additionally, if http://myapp.com/ sets cookies, you'll need to use the ProxyPassReverseCookieDomain and ProxyPassReverseCookiePath directives to rewrite those.

Resources