Unable to Set HTACCESS to url_rewrite - linux

I have .htaccess in the root of my project but its not re-directing as expected.
My app is trying to call:
http://localhost:8888/api/User //via mamp
But my node backend is running and anything after API may change due to the endpoint:
http://localhost:1377/projname-api/User //via node
I have tried:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^localhost:8888/api
RewriteRule (.*) http://localhost:8888/projname-api/$1 [R=301,L]
But i get a 500 server error in htaccess. I have re-written url's in .htaccess before but can not understand what i'm doing wrong.
Any help would be greatly appreciated.

Related

htaccess file - root and website folder htaccess file both have different code. URL does not work without the www

I have the following domain that does not work without the www.
wwww.mydomain.com works
mydomain.com = does not work
The root htaccess file (primary domain is something else) automatically seemed to have this code in it.
# php -- END cPanel-generated handler, do not edit
RewriteCond %{HTTP_HOST} ^mydomain\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.mydomain\.com$
RewriteRule ^/?$ "https\:\/\/www\.mydomain\.io\/mydomain" [R=301,L]
I added this code in the website's own htaccess file.
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
What am I doing wrong?
Currently mydomain.com goes to something quite strange (it duplicates the domain name): and has an error
https://www.example.com/example.com/
Error on page
Not Found
The requested URL was not found on this server.
Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
Can I delete the code which says "do not edit". Which one is working and why/how? A fix with an explanation would be appreciated.
The issue was basically resolved by:
Adding the rewrite engine rules:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
Deleting the forwarding in the DNS management console and ONLY leaving in the forwarding in the addondomains section. So, in the cpanel - addon domains, create forwarding and delete the forwarding in the DNS section. This was the key part.
There was an additional folder outside of the public_html for this domain and that was deleted as well.
Finally, adding these rules to force https was useful:
https://www.hostinger.co.uk/tutorials/ssl/forcing-https
Also noting the helpful comment: "Which web server are you using? Look through your web server configuration files. Your problem is that you have a redirect from HTTP to HTTPS and the path URL is configured wrong."

HTTP 500 Error Ionos with TYPO3 because of Rewrite Non-www to www in .htaccess

I got the following code in my .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} ^example.de [NC]
RewriteRule ^(.*)$ https://www.example.de/$1 [L,R=301,NC]
</IfModule>
If I call the url without "www" everything works fine! But with "www" it ends with http 500 error!
So on my development Server erverything works fine, with and without www!
On Ionos Server I can do what I want I guess.
I got https://www.expample.de in my Siteconfiguration of TYPO3 9.5 but it doesnt matter. Does anybody know a solution?
I think this is maybe not a .htaccess problem?!
Fix for IONOS hosted TYPO3 installations where adding www to the URL gives a 500 error:
Go to your install tool, /typo3/install.php should be accessible with www in the URL.
Go to Settings and open Configure Installation-Wide Options
Under [SYS][trustedHostsPattern] where SERVER_NAME is set by default, add your domain, for example. .*\.domain\.com (There are other examples given in the install tool).
Save these changes, the website is now accessible with www.

htaccess redirect without losing url

I want my website to redirect from https://www.sitename.com/single-product/supplier-name/supplier-id/article-name/article-id to https://www.sitename.com/single-product and want the same original URL restored.
Currently, https://www.sitename.com/single-product/supplier-name/supplier-id/article-name/article-id URL gets me to 404
I know I will have to use the P flag in .htaccess file in document root to get this working. But I don't know why my solution is not working
RewriteCond %{REQUEST_URI} ^/single-product
RewriteRule ^(.*)$ /single-product/$1 [P]
I have found a solution not it is not working on my server. I guess mod_proxy is currently off on my server
RewriteEngine on
RewriteRule single-product/* https://www.sitename.com/single-product/ [P]
This is a great website to test these scripts
https://htaccess.madewithlove.be/

500 Internal Server Error in my wamp server while trying to Rewrite URL in .htaccess

I'm trying to rewrite my bulky, ugly url to a neat one which is converting "art.php?id=$1" in to "art/1", but I encounter a "500 Internal Server Error" What shall I do? Can you help me pleeeease?
This is the .htaccess code I used:
RewriteEngine On
RewriteRule ^art/([A-Za-z0-9-]+)/?$ art.php?id=$1 [NC,L]
This is the Error I encountered:
Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request. Please contact the server
administrator, admin#localhost and inform them of the time the error
occurred, and anything you might have done that may have caused the
error. More information about this error may be available in the
server error log.
Thanks!
Supposed everything is in the gallery folder, which itself is located in the www root directory. Then put this .htaccess file into the gallery folder as well
RewriteEngine on
RewriteBase /gallery/
# prevent endless loop
RewriteCond %{ENV:REDIRECT_STATUS} 200
RewriteRule .* - [L]
# serve real content
RewriteRule ^art/([A-Za-z0-9-]+)/?$ art.php?id=$1 [NC,L]
# make pretty URL
RewriteCond %{QUERY_STRING} id=(.+)
RewriteRule ^art.php$ art/%1? [R,NC,L]
Depending on the server you're on, you might want to set the base for rewriting
RewriteEngine On
RewriteBase /art/
RewriteRule ^([A-Za-z0-9-]+)/?$ art.php?id=$1 [NC,L]
that should work just fine

ISAPI_Rewrite 3.0 ... Noob ... how to get started? just installed

just installed v3 lite to try it out before getting full version.
i got the follwing in .htaccess file in the root folder of the .net web app
RewriteEngine On
RewriteCond %{HTTPS} (on)?
RewriteCond %{HTTP_HOST} ^zzzz-wildcard\.domain\.com
RewriteRule ^(.*)$ http://domain.com/zzzz-wildcard$1 [R]
problem is it doesn't do anything. i got the wildcard set up on iis so that
test.domain.com is served just as domain.com would be.
What i want to achieve is to serve any sub-domain user1.domain.com as domain.com/zzzz-wildcard
from what i got so far even explicity supplying zzzz-wildcard.domain.com still serves the default.aspx of the domain.com instead of domain.com/zzzz-wildcard/default.aspx
please help. i have never worked with isapi rewrite so i have no clue how to go about this.... right now as it stand it doesn't really do anything. can't say i'm good with regular expressions either :(
When opening ISAPI_Rewrite Manager and selecting my domain.com from the list of iis websites it says No properties available for this node.
******** EDIT ********
after some more looking around i found out that lite version doesn't support .htaccess so only httpd.conf file that works globally. So anyway i modified the httpd.conf file instead and it now works..
however it just redirects zzzz-wildcard.domain.com to domain.com/zzzz-wildcard
Is there a way to keep the url intact and not redirect? but still serve the pages from domain.com/zzzz-wildcard ?
finally solved after looking around other answers on stackoverflow
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.domain\.com$ [NC]
RewriteCond %{HTTP_HOST} ^(.*?)\.domain\.com$ [NC]
RewriteRule (.*) /zzzz-wildcard/%{REQUEST_URI} [NC]

Resources