for some strange reason in Google Chrome one of my scripts is having serious problems. I'm setting up a page that requires twitter/facebook connections. Basically what you are doing is:
visit page (Facebook+Twitter class are started, some session settings are being set etc)
Click the connect button for one of the networks
fill in your connection details
sign up at our website (clicking submit).
Now everything works perfectly in IE/Firefox/Safari, however Chrome is doing some really crazy stuff. I would like to ask you to visit this page:
Not Important Anymore
Most likely in Firefox/IE/Safari it will just display an empty var_dump() of the $_SESSION variable. At first this is what it does in Chrome aswel, BUT! If you refresh the page once in Firefox/IE/Safari the session is still empty, but in Chrome it is showing some keys already.
I have absolutely no clue where these keys come from.. this is the content of viewsessions.php:
session_start();
echo '<pre>';
var_dump($_SESSION);
if(isset($_GET['u'])) {
unset($_SESSION);
}
As far as I know there cannot happen anything else but the above and Firefox/IE/Safari are showing the right behaviour.
It wouldn't be a big problem if everything was working fine, but al the 'requestoken_XXXX' session keys belong to the Twitter OAuth.. and because the requesttoken is refreshed on everypage the Authentication redirect to my website can not find a matching token and thus not validate the authentication.
Can anyone see what is happening? Is some page being called in the back? Is this some Chrome related issue that is known? I really don't have any clues left what this could be..
Thanks in advance.
Problem solved..
For some reason this file:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
Options -Indexes
RewriteEngine On
RewriteBase /
# Bestaande bestanden of mappen uitsluiten
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*?)$ $1 [L]
RewriteRule ^start/$ login.php [L,QSA]
RewriteRule ^logout/$ logout.php [L,QSA]
RewriteRule ^timeline/$ timeline.php [L,QSA]
RewriteRule ^(.*)$ index.php [L]
</IfModule>
Did some request to index.php (I guess...), seems a bit odd because I have stated that if it's an existing file or directory it should just open the file: RewriteRule ^(.*?)$ $1 [L] and I also flagged it as the last rule to follow.
Removing this last RewriteRule solved the problem. Still not sure why Chrome overrules the [L] parameter.. if anyone could explain it, that would be awesome.
Related
I've got a working SSL certificate, but the only way for a person to visit my https website is by typing "https://" in the search bar. I've got a .htacces file that contains the following code:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
And I also tried this line of code:
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
But neither of them seem to work.
I've also read that there is a meta tag that sends all users to your https no matter what. But still have yet to find what the meta tag looks like.
Any help is appreciated. Thank you for your time
The basic idea is correct - you will need rewrite rules on your webserver for to make the site HTTPS only
RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
Please take a look at the following documentation: https://wiki.apache.org/httpd/RewriteHTTPToHTTPS
Regarding why your rules are not working - you need to know the context of .htaccess file, from documentation:
.htaccess files (or "distributed configuration files") provide a way
to make configuration changes on a per-directory basis. A file,
containing one or more configuration directives, is placed in a
particular document directory, and the directives apply to that
directory, and all subdirectories thereof.
it is however better not to use .htaccess at all if possible since it has negative performance implications and the same thing can be achieved with <Directory> blocks. All of that is in here: https://httpd.apache.org/docs/current/howto/htaccess.html
Regarding the meta tag - all you need to do is add something like this:
<meta http-equiv="refresh" content="0; url=https://yoursite.com/">
The meta tag is definitely not the best practice of HTTP-2-HTTPS redirection due to the fact that it is easy to circumvent and outside of webmasters control since it's a client side redirect.
I have a static website that has several html pages. In order to not hide .html extensions from url, we have following rules in htaccess for each url:
RewriteRule ^website-development$ website-development.html
This works fine in that if you open site.com/website-development, it actually opens the website-development.html file but in url it does not show the .html extension.
Now, we need to redirect(or hide) .html urls to their corresponding urls without .html e.g. if someone opens site.com/website-development.html in their browser, the url should be shown as site.com/website-development.
To do this, I added following rule:
RewriteRule ^(.*)\.html$ /$1 [L,R]
But doing this results in indefinite redirection and so the browser just keeps redirecting and never renders the actual page. Can you please suggest how I can redirect both site.com/website-development and site.com/website-development.html to site.com/website-development (which actually is an html file - website-development.html ). Thanks.
Yes indeed, this rule will cause a redirect loop:
RewriteRule ^(.*)\.html$ /$1 [L,R]
It is due to the fact your REQUEST_URI is adding and removing .html in 2 different rules and mod_rewrite runs in a loop.
You can use this rule instead based on a RewriteCond that uses THE_REQUEST
RewriteCond %{THE_REQUEST} \s/+(.+?)\.html[\s?] [NC]
RewriteRule ^ /%1 [R=301,NE,L]
THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules. Example value of this variable is GET /index.php?id=123 HTTP/1.1
I started seeing 404 errors in my logs for urls like:
http://site.example.com/foo/bar.html%23anchor
Clearly the #anchor was being encoded (probably in someone else's email that I can't control) resulting in broken links. The anchor links are not that important, but I don't want my users seeing 404 pages. I thought I could fix this with a simple rewrite, but nothing I have tried has worked and none of the SO answers I looked at worked.
The rewrite codes I tried worked perfectly in RegExr and regex101, but when I try it in my .htaccess, the bad link still results in a 404 error. I have other RewriteRules working, but I can't seem to remove the unwanted %23anchor from the end of the request.
RewriteEngine on
RewriteBase /site
## Externally redirect non-canonical domain requests to canonical domain. ###
## This rule works ###
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ http://site.example.com/$1 [R=301,NC,L]
## This rule doesn't work ###
RewriteRule ^(\.html)(%23)(.*)$ $1 [R=302,NE,L]
I need to change this:
http://site.example.com/foo/bar.html%23anchor
into this:
http://site.example.com/foo/bar.html
What am I missing?
You are missing everything in front of ".html". Try this rewrite:
RewriteRule ^(.*\.html)(%23)(.*)$ $1 [R=302,NE,L]
https://regex101.com/r/fV3oU3/1
Thank you for all of your suggestions, but none of them solved the initial problem. Because the RewriteBase rule affects all relative rewrites, I could not see a way to write this rule as I originally intended. In the end the only thing that seemed to work was to rewrite to an absolute path. This is the rule I ended up with. It is not flexible and only works for this page, but at least it fixes the specific broken link I am currently trying to correct:
RewriteRule ^(.*bar\.html)\x23.*$ http://site.example.com/foo/bar.html [R=302,NE,L,NC]
The above rule rewrites this: http://site.example.com/foo/bar.html%23anchor
to this: http://site.example.com/foo/bar.html
Replace your last rule with this:
RewriteRule ^(.+?\.html)\x23 /$1 [R=302,NE,L,NC]
%23 is matches by \x23 in RewriteRule.
Is there a way to link to the index page of a website without specifying the name of the index page or the full website URL?
I have this:
Home
But when I click the link, my address bar shows:
mydomain.com/index.html
I would like it to show:
mydomain.com
Can I do that without putting the full URL (mydomain.com) in the href? If so, how?
For future viewers, I also found this question helpful.
You can just do this:
Home
Any href preceded by a slash is relative the root directory.
It should be noted that when viewing a webpage from a local hard drive in a browser, this will cause the link not to function.
I know this post is old and has an answer. But here is my contribution that also supports index that is not exactly in the root directory
to goto
mydomain.com/index.html
without index.html showing in address bar
Home
this will always point to mydomain.com no matter where the directory your file was saved to.
to point to the index in a directory use this:
Home
this will point to mydomain.com/subdir for mydomain.com/subdir/index.html while the accepted answer will always point to mydomain.com (and this is not always the desired action)
Create a ".htaccess" file and upload to your host public folder
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.html\ HTTP/
RewriteRule ^index\.html$ http://www.yourwebsite.com.ph/ [R=301,L]
RewriteCond %{THE_REQUEST} \.html
RewriteRule ^(.*)\.html$ /$1 [R=301,L]
</IfModule>
Part One
I want to .htaccess redirect all HTML files to the home page. I looked at this guy's question (htaccess redirect all html files), and wrote this code:
RewriteCond %{HTTP_HOST} ^pandamonia.us$ [OR]
RewriteCond %{HTTP_HOST} ^www.pandamonia.us$
RewriteRule .*\.html$ "http\:\/\/pandamonia\.us\/" [L]
but the problem is that it also redirects the homepage to itself, causing the universe to end.
So my question, is how can I redirect every HTML page that is not the homepage to the homepage.
Part Two
Exclude certain subfolders and domains in redirects
Try changing .* to .+ in the regexp, that should mean 'at least one character' instead of zero or more characters, so the empty string should be avoided.
Wait. The initial '/' is included. Try it like:
RewriteRule /.+\.html$ "http\:\/\/pandamonia\.us\/" [L]