404 Page not found using form submission - apache

In localhost all is okay.
But I have a hosting where in the /public_html/site folder I have the main WordPress site. I have another PHP site which has no htaccess in /public_html/site/BETA.
You can login here: http://yoursocialtool.com/BETA/login.php
User: stack
Password: overflow
Now the problem is when I am trying to logout after login using a form submission to the same page like as http://yoursocialtool.com/BETA/dashboard.php it says:
404 Page not found!
But if I directly put the url in the browser address bar http://yoursocialtool.com/BETA/dashboard.php then its loading fine without any 404 error.
The .htaccess in /public_html:
RewriteOptions inherit
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursocialtool.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.yoursocialtool.com$
RewriteCond %{REQUEST_URI} !site/
RewriteRule (.*) /site/$1 [L]
The .htaccess in /public_html/site:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /site/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /site/index.php [L]
</IfModule>
# END WordPress
Here is the codes which I am using in my dashboard.php:
<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
ini_set('error_log','error.log');
require("config.inc.php");
require("__require_login.php");
require_once("_isconnected.php");
if (isAppLoggedIn()){
require("_dashboard.html.php");
} else {
echo ($msg);
?>
<script>
window.location = "./login.php?from=dashboard&location=";
window.location.assign("./login.php?from=dashboard&location=assign");
</script>
<?php
}
?>
And the problem which I am facing is that the code is not executing JavaScript redirect in the server after login. Actually its not getting the dashboard.php after I am submitting the logout request although it seems to have logout successfully. I am handling the logout action in the dashboard.php also. Seems to be that the /public_html/site/index.php is handling it only after the logout submission.
N.B: My localhost have only the part of the site under /public_html/site/BETA. So the localhost does not have any htaccess or wordpress.

In localhost all is okay.
Only because it works on localhost it must not need to work everywhere. This is why it is inherently important that your development version of the server-configuration is close (if not identical) to the server-configuration you deploy it to later on.
For that use virtualization and try to reproduce the 404 on your localhost then.
Getting the same behavior on both ends is a first sane check to do in troubleshooting the issue. From the current information you provide in your question this is the best suggestion I can give.
The short answer is: The configuration between both systems differ. Take care you are able to use the same configuration on both systems which includes not only configuration directives but also the same version of all softwares involved, for example the same version of the webserver, the same operating system and the same version of PHP (albeit PHP does not seem to be the issue here).

I moved the site to a subdomain. After that I see 500 error with 404.
I have found out the solution consulting with the Apache system administrator. They had showed me that there was error in the log like below:
malformed header from script. Bad header=
Then I found that the server is not supporting the redirection in server side php script. Then I disable the redirection in server and now its working fine. I used JavaScript redirect.
<?php
//header('Location: http://www.example.com/');//Use JavaScript to redirect instead. Comment it out
exit;
?>
If someone must need the redirection then may try using the construct exit; just after the header declaration. Otherwise use JavaScript.

Related

Unable to find the source of a rewrite

I'm trying to setup an apache server with a somewhat complex htaccess rules. I have found various solutions for individual rules, however, when I try to put the whole picture together I lack experience with htaccess to make it work and I experience some weird rewrites.
Rules:
The root contains index.php which launches a single page UI app. That means that URLs should be rewritten to /index.php
There are a few folders which should be exempt from Rule #1, e. g. if /admin is accessed, /admin/index.php should be shown, not /index.php.
Rule #2 also applies to all files on the server (so that the UI app can load resources like js/css/etc.)
All http://* requests should be redirected to https://*
Some possibly relevant details:
The server has a LetsEncrypt SSL certificate installed. The "redirect from http" was enabled during installation, I figured it might've created some weird rewrite rules, so I navigated to etc/apache2/sites-available/lamp-server.conf and commented out these three lines
#RewriteEngine on
#RewriteCond %{SERVER_NAME} =[DOMAIN]
#RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
Here's the relevant part of /.htaccess. There are no other rewrites/redirects in this file.
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/(wp|admin|phpmyadmin)(/.*)?$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* /index.php [QSA]
RewriteCond %{HTTPS} !on
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R]
When I clear the cache in browsers, it seems to work correctly for a while. But when I open the SPA part of the server (i. e., the first RewriteRule is triggered), the browser caches some sort of rewrite and then /admin also starts pointing to the SPA, unless I do a Ctrl+F5 each time.
I tried executing GET requests via Fiddler 4, everything seems to be working correctly there. Tried these scenarios:
HTTP root - got a 302 redirect.
HTTPS root - 200 OK.
/search SPA page - got 200 OK with rendered /index.php as response.
/admin page outside of SPA - got 200 OK with rendered /admin/index.php as response.
During the development of the htaccess rules there might've been a time when a 301 redirect was executed, which is now messing with my browser cache. However, then it's weird that even if I install a new fresh browser, it gets affected by the issue. Even if I try to access it from my mobile (which I never did before, so there's nothing cached), the same issue happens.

Giving 404 for only '/' route (Nuxt JS) - Shared Hosting Deployment

I am trying to set up a Nuxt app using #nuxt/pwa starter-template for Server Side Rendering on a Shared Hosting.
However my Nuxt app is running on "http://localhost:50000". I am trying to show the running app from "http://example.com" by Rewriting Rule in .htaccess.
When trying to access "http://example.com" it's showing 404. Without the "Index (/)" route every other route is fine. Even coming to "Index (/)" route from any other route is also OK. Only showing 404 when trying to load the "/" route directly.
Eg:
http://example.com Doesn't work
http://example.com/contact Works fine
*** There is already an issue exactly like mine at Github: https://github.com/nuxt/nuxt.js/issues/2625
But I couldn't found anything helpful from there.
Here is the .htaccess file I am using. --
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^(.*) http://127.0.0.1:50000/$1 [P,L]
</IfModule>
Can somebody help me out with this issue??? Thanks in advance!
It seems to be a bit late for this answer, but I only found it in github and would like to help anyone who finds this topic with the same problem.
This htaccess is working for me, it loads the index.vue page normally when I refresh and the navigation works.
Replace my-domain with your domain.
RewriteEngine on
# Forcing all incoming requests to HTTPS.
# HTTPS is required for PWA. If you don't want PWA feature you can deisable next 2 lines
RewriteCond %{HTTP_HOST} ^my-domain.com.br$
RewriteRule "(.*.(jpg|gif|png|svg|js|css|woff2))$" "http://127.0.0.1:3000/$1" [P,NC]
RewriteRule ^(.*) "http://127.0.0.1:3000/$2" [P,L]
Use my .htaccess code:
RewriteRule ^index.html.var$ http://127.0.0.1:3000/ [P]
RewriteRule ^(.*) http://127.0.0.1:3000/$1 [P]
This problem has also troubled me for a long time.
I added _index.vue dynamic vue-router and,
validate ({params}) {
console.log (params.index);
}
The terminal outputs "index.html.var".
So I was thinking that when we visited the homepage, Apache sent a proxy, but the request URL received by nuxt.js was not "/" but "index.html.var".
A little late to this party but if anyone is experiencing the same issue, what fixed it for me was to disable DirectoryIndex in .htaccess.
RewriteEngine on
DirectoryIndex disabled
RewriteRule ^(.*) http://127.0.0.1:50000/$1 [P,L]
RewriteEngine on
Forcing all incoming requests to HTTPS.
HTTPS is required for PWA. If you don't want PWA feature you can deisable next 2 lines
RewriteCond %{HTTP_HOST} ^my-domain.com.br$
RewriteRule "(..(jpg|gif|png|svg|js|css|woff2))$" "http://127.0.0.1:3000/$1" [P,NC]
RewriteRule ^(.) "http://127.0.0.1:3000/$2" [P,L]
Work for me.

How to setup request proxy using URL rewriting

I have an e-commerce site that resides in:
http://dev.gworks.mobi/
When a customer clicks on the signin link, the browser gets redirected to another domain, in order for authentication:
http://frock.gworks.mobi:8080/openam/XUI/#login/&goto=http%3A%2F%2Fdev.gworks.mobi%3A80%2Fcustomer%2Faccount%2Flogin%2Freferer%2FaHR0cDovL2Rldi5nd29ya3MubW9iaS8%2C%2F
I'm trying to rewrite http://dev.gworks.mobi/* to http://frock.gworks.mobi:8080/openam/*, without redirection.
I've tried this in the .htaccess of the dev.gworks.mobi site:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/openam(.*)$ [NC]
RewriteRule ^(.*)$ http://frock.gworks.mobi:8080/$1 [P,L]
</IfModule>
But when I access http://dev.gworks.mobi/openam, it shows a 404 page not found page.
Can anyone help me to achieve my use case?
Try this:
RewriteEngine on
RewriteBase /
# Make sure it's not an actual file being accessed
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Match the host
RewriteCond %{HTTP_HOST} ^dev\.gworks\.mobi
# Rewrite the request if it starts with "openam"
RewriteRule ^openam(.*)$ http://frock.gworks.mobi:8080/$1 [L,QSA]
This will rewrite all the requests to dev.gworks.mobi/openam to frock.gworks.mobi:8080.
If you want to mask the URI in a way that it's not visible to the visitor that she's visiting the authentication app, you need to add a P flag. Please note that it needs Apache's mod_proxy module in place:
RewriteRule ^openam(.*)$ http://frock.gworks.mobi:8080/$1 [P,L,QSA]
Feel free to drop the L flag, if it's not the last rewrite rule. See RewriteRule Flags for more information.
The 404
If it's all in place and you're still getting a 404 error, make sure that the target URL is not throwing 404 errors in the first place.
Second, check if you're still getting the error with the correct referrer URI set. It might be designed in a way to throw a 404, if the referrer is not correctly set. If that's the case, which I suspect, you need to use the R flag and redirect instead of proxying the request.
Last thing that comes to my mind, some webapps are not built in a way to figure out the URI address. The host, as well as the port number, might be hard-coded somewhere in the config files. Make sure that the authentication app is able to be run from another URL without the need to edit the configs.
Test
You can test the rewriterule online:

force SSL for single .html page without php or anything else just using .htaccess

After several hours of trying a myriad of suggestions for .htaccess I have given up and decided to ask here.
I have a single html page that needs to be served via SSL. It is a single file with the .htm extension and it contains no php whatsoever. If anybody accesses this page via typing it in or clicking on a link from a non SSL page, I want that person to be redirected to or shown the SSL version of that page. Only https://example.com/myfile.htm should be allowed. The rest of the site can go without SSL, just this one page needs it.
Please help.
Try this in your .htaccess file.
RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule ^myfile\.htm$ https://www.example.com/myfile.htm [R=301,L]
Try:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^myfile\.htm$ https://example.com/myfile.htm [L,R]
SSL for HTML only page / SSL for JavaScript only page:
If anyone needs to set SSL (HTTPS) for page that uses html only (without PHP, nodeJS etc.) just put .htaccess file in the same folder as index.htm page.
Content of the .htaccess have to be:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I had trouble finding how to, so I think that this thread is the best to hold this answer.

Prestashop redirects me to install/

I have set up prestashop CMS and remove install directory, but when I try to open my site link www.mydomain.com, I have redirected to www.mydomain.com/install/ and CMS says, that page not found (404).
But if I open www.mydomain.com/index.php all works fine!
Why CMS not redirect me from www.mydomain.com to www.mydomain.com/index.php automatically?
As i dont know what may be causing this issue, but Please do the following steps. One may fix your issue.
1) Clear your Browser cache.
2) Go to Preferences -> SEO & Urls at PS admin. Down the page, you will have some three options
a) Friendly URL
b) Automatically redirect to Canonical URL
c) Disable apache multiviews
Enable / disable them alternatively and try to load the page.
Also after you enable / disable these features it will be good if you clear your browser cache before loading front page.
Some times i myself get such issues and i fix them like these and it works for me, still i dont know why this issue occures :P
Hope this will help. And if it does not work, let me know.
Thank you
I think there is an incorrect rule got created in your htaccess file. (It's in the root folder)
Open htaccess file (keep a copy of it on your desktop) and the code within # Dispatcher should look like below:
# Dispatcher
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteCond %{HTTP_HOST} ^www.yoursite.com$
RewriteRule ^.*$ - [NC,L]
RewriteCond %{HTTP_HOST} ^www.yoursite.com$
RewriteRule ^.*$ %{ENV:REWRITEBASE}index.php [NC,L]
</IfModule>
Just check and let me know.