I have been tasked to migrate an old project running on aws to vps based cpanel, I have done the following:
setup to cpanel to accept (only) php 5.6 & it's extensions, also setup exported db & it's credentials to required file.
the path to the project is setup directly on the public_html/ folder
the .htaccess file has been configured following :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^$ app/webroot/ [L]
</IfModule>
which i took from the cakephp installation documentation & added some - Link
The original project htaccess was a bit different however :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} example\.com [NC]
RewriteCond %{SERVER_PORT} 80
php_value max_input_vars 100000
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} =http
RewriteRule .* https://%{HTTP:Host}%{REQUEST_URI} [L,R=permanent]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule (.*) app/webroot/$1 [L]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/cpanel-dcv/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/(?:\ Ballot169)?
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^$ app/webroot/ [L]
</IfModule>
& removing the htaccess or not using it at all in both projects produces same error
Warning (2): scandir(../View/Ipac): failed to open dir: No such file or directory [APP/Config/routes.php, line 32]
Warning (2): scandir() [function.scandir]: (errno 2): No such file or directory [APP/Config/routes.php, line 32]
Warning (2): Invalid argument supplied for foreach() [APP/Config/routes.php, line 32]
I have tried to use the same htaccess in the new migration along with every other rule which 'seems' okay to me but it shows me internal server error. Now I am stuck here
Internal Server Error The server encountered an internal error or
misconfiguration and was unable to complete your request. Please
contact the server administrator at webmaster#example.com to inform
them of the time this error occurred, and the actions you performed
just before this error.
More information about this error may be available in the server error log.
Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request. Does anyone know how can I fix this. Any help is appreciated.
Okay, turns out that after 2 days of losing my mind on this, the issue was due to the htaccess set incorrectly in the app/webroot (which I missed) & also it's index file had a file permission of 775, which cpanel doesn't allow to be viewed publicly, setting those correctly booted the project up perfectly.
Related
subdomain is unchanged:
loja
Old domain:
loja.churrascoelareira.com.br
new domain
loja.bomdebrasa.com
The thing is that google is still sending visitors to urls like this:
loja.churrascoelareira.com.br/exemple-product-page.html
How can I forward that to:
loja.bomdebrasa.com/exemple-product-page.html
with wildcards?
EDIT1:
The file is like the following (both domains point to the same server) and this file is located in tow folders (just to make sure): public_html and public_html/churrascoelareira.com.br
Bellow this code there is an image of the cPanel's parked domain.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ $1.php [L]
# Google Analytics Integration - Added by cPanel.
<IfModule mod_substitute.c>
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|(<script src='/google_analytics_auto.js'></script>)?</head>|<script src='/google_analytics_auto.js'></script></head>|i"
</IfModule>
# END Google Analytics Integration
RewriteCond %{HTTP_HOST} ^bomdebrasa\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.bomdebrasa\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^/?$ "http\:\/\/www\.bomdebrasa\.com\/newsite\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^bomdebrasa\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.bomdebrasa\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^site\/?$ "http\:\/\/bomdebrasa\.com\/newsite" [R=301,L]
RewriteCond %{HTTP_HOST} ^bomdebrasa\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.bomdebrasa\.com$
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^site\/produtos$ "http\:\/\/bomdebrasa\.com\/newsite" [R=301,L]
RewriteCond %{HTTP_HOST} ^loja\.churrascoelareira\.com\.br$
RewriteRule ^/?(.*)$ https://loja.bomdebrasa.com/$1 [R=301,QSA]
# php -- BEGIN cPanel-generated handler, do not edit
# NOTE this account's php is controlled via FPM and the vhost, this is a place holder.
# Do not edit. This next line is to support the cPanel php wrapper (php_cli).
# AddType application/x-httpd-ea-php56 .php .phtml
# php -- END cPanel-generated handler, do not edit
cPAnel's parked domain:
EDIT2:
I finally found where (in this outdated cPanel version) to do the redirects with wildcards. So this is solved (not by manually creating the file, but solved) and I checked the .htaccess file that was already there and saw nothing new, so I guess it was done in another way.
Not sure what you mean by "wildcard" here, but this rule setup should forward those requests to the new domain, if it is implmented in the old http host:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^loja\.churrascoelareira\.com\.br$
RewriteRule ^/?(.*)$ https://loja.bomdebrasa.com/$1 [R=301,QSA]
For this to work you obviously need to have the rewriting module enabled and loaded in the old http host. The rule set will work likewise in the http server's host configuration or inside a dynamic configuration file (".htaccess"), you should however prefer the first option. If you decide to use a dynamic configuration file then take care that it's interpretation is enabled for the old http host and that the file is located in the host's DOCUMENT_ROOT folder and readable by the http server process.
I am trying to run a nodejs application on shared hosting and successfully installed node/npm following this tutorial from A2Hosting:
https://www.a2hosting.com/kb/installable-applications/manual-installations/installing-node-js-on-managed-hosting-accounts
I am now on INTEGRATING A NODE.JS APPLICATION WITH THE WEB SERVER part and when I copied the rewrite rules to the .htaccess file, it runs the node on the root domain instead of the wordpress website. Here is my .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
# BEGIN Node
# RewriteRule ^$ http://127.0.0.1:49876/ [P,L]
# RewriteCond %{REQUEST_FILENAME} !-f
# RewriteCond %{REQUEST_FILENAME} !-d
# RewriteRule ^(.*)$ http://127.0.0.1:49876/$1 [P,L]
# END Node
I wanted the nodejs app to run on the subdomain like: subdomain.domain.com and keep the wordpress running on: domain.com
What changes should I make to the nodejs rewrite rule to make it run on subdomain.
CPANEL with AutoSSL (Let’s Encrypt) add automatic RewriteCond to htaccess because .well-known folder and keep updating htaccess file every X minutes, so you can't delete the "well-know" lines. But with this approach they break RewriteRule back reference to RewriteCond.
# www to non-www generic
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
This example above don't work as spectated because %1 references last RewriteCond, and not the first where we filter the host with regexp.
Some fix for generic www to non-www, using variables
# www to non-www (fixed to work with CPANEL - AutoSSL)
SetEnvIf Host "^www\.(.*)$" my_domain=$1
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/\.well-known/acme-challenge/[0-9a-zA-Z_-]+$
RewriteCond %{REQUEST_URI} !^/\.well-known/pki-validation/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://%{ENV:my_domain}/$1 [R=301,L]
To bypass this problem use variable, it's not pretty but works!
I have an .htaccess file with this
Options FollowSymLinks
RewriteEngine on
#RewriteCond $1 !^(index\.php|images|assets|layout|avatars|custom|js|media|script|skin|uploads|isAjax|robots\.txt)
# To be deployed on LIVE only
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301]
# Everything else to the CI controller
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
But when I open my site, Show me :
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Thanks all for your Help.. :)
I want to make my htaccess file redirect all traffic except that to /images, /css, and /javascripts to the cgi-bin.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^images/.*$
RewriteCond %{REQUEST_URI} !^css/.*$
RewriteCond %{REQUEST_URI} !^javascript/.*$
RewriteCond %{REQUEST_URI} !^cgi-bin/.*$
RewriteRule (.*) /cgi-bin/$1 [L]
I want a request for: example.com/index to retrieve example.com/cgi-bin/index
but I also want a request for: example.com/images/foo.png to retrieve example.com/images/foo.png
What is wrong with my file? I keep getting this error: Request exceeded the limit of 10 internal redirects due to probable configuration error.
You are missing the leading / in all of your RewriteConds, which are required, though they should not be used for RewriteRule in .htaccess, which does cause confusion.
RewriteEngine on
RewriteCond %{REQUEST_URI} !^/images/ [NC]
RewriteCond %{REQUEST_URI} !^/css/ [NC]
RewriteCond %{REQUEST_URI} !^/javascript/ [NC]
RewriteCond %{REQUEST_URI} !^/cgi-bin/ [NC]
RewriteRule (.*) /cgi-bin/$1 [L]
You also don't need the .*$ so I removed them to make it more efficient.