I"m trying to set up a laravel project as the main page for this cpanel, I'll be blurring out the website name and such for privacy reasons. I've made a redirect to the directory like this
When I click on the directory link, I get sent to the project but get these errors
Refused to apply style from 'http://page_example.com/css/app.css?id=4513b702e5714c4239c0' because its MIME type ('text/html') is not a supported stylesheet MIME type, and strict MIME checking is enabled.
If I try and go into the website just the page without the /ex_server/public I get redirected to just page_example.com/ex_server without the /public and I get a 403 forbidden.
I don't think the redirect is even working, because in the index.php file in the public_html file I have this, If I leave only the first two default blocks of code then I get redirected to the default a2hosting page, but if I comment that first stuff out and only leave the manual redirect then I do get redirected to that page.
<?
if (file_exists('./index.html')) {
rename('./index.php', './a2-default-index.php');
header('refresh:1');
}
$ch = curl_init('http://default.a2hosting.com/');
curl_exec($ch); curl_close($ch);
?>
<?php
header("Location: http://www.page_example.com/ex_server");
die();
?>
How can I fix these errors and get the redirect working correctly?
You can try this add this file
.htaccess file to public_html folder
RewriteEngine on
# for example.com rewrite landing page to subdirectory/index.php
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^/?$ subdirectory/index.php[L]
# for example.com rewrite all other URIs to subdirectory/uri
# (?!subdirectory/) is a negative lookahead that stops rewrite then uri
# already starts with /subdirectory/
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^(?!subdirectory/)(.+)$ subdirectory/$1 [L,NC]
Change subdirectory to home and example to your domain name.
Related
I have added .php extension to all my pages in wordpress through functions.php.
My Code -
<?php
// Do NOT include the opening PHP tag
// Add .PHP to page permalinks
add_action('init', 'ss_php_pages', -1);
function ss_php_pages() {
global $wp_rewrite;
if ( !strpos($wp_rewrite->get_page_permastruct(), '.php')){
$wp_rewrite->page_structure = $wp_rewrite->page_structure . '.php';
}
$wp_rewrite->flush_rules();
}
// Remove slash from page permalinks
add_filter('user_trailingslashit', 'no_page_slash_on_ss',66,2);
function no_page_slash_on_ss($string, $type){
global $wp_rewrite;
if ($wp_rewrite->using_permalinks() && $wp_rewrite->use_trailing_slashes==true && $type == 'page'){
return untrailingslashit($string);
}else{
return $string;
}
}
Now I want to redirect my old link (example.com/demo) to new link (example.com/demo.php)..
I have many pages there so I can't add redirection for each manually.
Additional information:
I have added .php extension to my Wordpress pages (example.com/demo + .php). Now My Old Links (example.demo or example.com/anything) which were without .php, got 404 because I have added .php to them so they have modified. Now I want to redirect my all old links like example.com/demo to example.com/demo.php or example.com/xyz to example.com/xyz.php to not to loss traffic or getting broken link.
You can redirect your non-php pages to php using RewriteRule directive in your WordPress htaccess.
At the top of your htaccess file , put the following rule :
RewriteEngine on
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.+?)/?$ /$1.php [L,R=301]
Could you please try following htaccess Rules. Make sure htaccess is present in root folder.
Make sure to clear your browser cache before testing your URLs.
RewriteEngine on
##User is using wordpress without this rule it was adding .php to home page too which was NOT needed, hence this rule is been added.
RewriteRule ^/?$ / [R=301,END]
##Major rules for links which are non php and should be served with php format files.
RewriteCond %{DOCUMENT_ROOT}/$1.php -f [NC]
RewriteCond %{REQUEST_URI} !\.php/?$ [NC]
RewriteRule ^(.*)/?$ $1.php [L,R=301]
For JS/CSS rewrite: You may need to use base tag to fix your js and other relative resources. If you are linking js files using a relative path then the file will obviously get a 404 because its looking for URL path. for example if the URL path is /file/ instead of file.html then your relative resources are loading from /file/ which is not a directory but rewritten html file. To fix this make your links absolute or use base tag. In the header of your webpage add this <base href="/"> so that your relative links can load from the correct location.
So I am making a new website, Link, but for some reason no folders have the full SSL icon. The top-level index.php file has the lock, but anything inside a folder, try /blog, has partial-ssl. It has the lock, but hides it because of the "Someone can change the look of this page" type error. Please help, as I do not know why this is hapenning. I do use cloudflare, and have set a http://qualexcraft.tk/* page rule to force https.
UPDATE: Now no folders or files have the full lock
For anyone interested, here is my htaccess file:
# Do not remove this line, otherwise mod_rewrite rules will stop working
RewriteBase /
ErrorDocument 404 http://qualexcraft.tk/404
# Redirect www urls to non-www
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.qualexcraft\.tk [NC]
RewriteRule (.*) https://qualexcraft.tk/$1 [R=301,L]
Directory Structure:
index.php
404
index.php
old.php
assets
images
blog
allPosts
index.php
includes
headers
head.html
index.html
layout
footer.html
navbar.html
maps
mdl
[mdl files]
One of the reasons for the bahaviour is the following line in your htaccess file:
ErrorDocument 404 http://qualexcraft.tk/404
When the client requests for the image https://qualexcraft.tk/blog/images/android-desktop.png, a 302 redirection to http://qualexcraft.tk/404 is triggered. This page, in turn, has a permanent redirection set to https://qualexcraft.tk/404.
Now, as I asked in the comment, there is another rule which adds a trailing / in the URLs and redirects it to http://qualexcraft.tk/404/. This, lastly; redirects with the status code 301 to the secure page: https://qualexcraft.tk/404/.
The intermediate redirects to http pages is the root cause of your problem. The same occurs when someone visits the blog link on your website.
The request to https://qualexcraft.tk/blog gets redirected to http://qualexcraft.tk/blog/ and then to https://qualexcraft.tk/blog/.
After your changes to the website, the behaviour is still the same, except that the request is now for https://qualexcraft.tk/favicon.ico.
Try updating your htaccess to the following:
Options -MultiViews
DirectorySlash Off
ErrorDocument 404 https://qualexcraft.tk/404
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)/?$ $1/index.php [L]
RewriteCond %{HTTP_HOST} ^www\.qualexcraft\.tk [NC]
RewriteRule (.*) https://qualexcraft.tk/$1 [R=301,L]
Add your favicon image to favicon.ico, to images/touch/ms-touch-icon-144x144-precomposed.png and to images/android-desktop.png. That is the only insecure content error that can be seen so once that is fixed you should be okay after clearing your browser cache.
In order to spot mixed content errors in the future, you can go to the console in Chrome (right click > Inspect Element > console) and your insecure content errors will be displayed there.
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.
I have a site that i want to redirect all requests accept for 1 directory path.
http://mysite.com/application
http://mysite.com/application/templates
http://mysite.com/application/admin (password protected)
RewriteCond %{REQUEST_URI} !^\/application
RewriteRule ^.*$ http://mynewsite.com [R=307]
My rewrite engine on the .htaccess is working fine, except when accessing the /admin directory which is password protected. When i try to request it, i am redirected. If i rename the .htaccess in the /admin folder. it works fine. My suspicion is that the browser (FF) is requesting another url which matches the redirect. How can i keep the directory password protected, but not redirect?
by adding:
RewriteCond %{REQUEST_URI} !401
Now it works. I believe this is due to the shared webhost configuration which has pre-assigned 4XX and 5XX page redirects. So, that that is what was happening. The !401 isn't perfect, but for my simple app it works. I think something like this would be better to capture 401 as the beginning of the uri (pattern is untested):
RewriteCond %{REQUEST_URI} !^\/401
What's the best way to redirect from web root (e.g., example.com) and the www subdomain (e.g., www.example.com) to a specified subdomain? I've not got great access to the server I'm working on, so editing .htaccess or similar would probably be the most practical solution.
In .htaccess:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^(.*)$ http://subdomain.example.com/$1 [R=301,L]
That'll do a 301 redirect and will include anything after the initial /, so example.com/page.html will go to subdomain.example.com/page.html
If you cannot edit configuration files, but can upload files to the root directory via FTP, you can also do it with severside script. In PHP, for example in an index.php:
<?php header("Location: http://sub.domain.com/"); ?>