My page is loading several times - .htaccess

My website is loading 3 times every time I go to
website/user/slug.
This is my htaccess file.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
#RewriteCond %{REQUEST_FILENAME} !\.(png|jpg|gif)$
#redirect to index.php?url=slug
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Anyone can give me a hint on how to solve this multiple loading?

So, This is not a complete answer but I'm updating this until I get the full answer.
As suposed on one of the answers, I'm using my own framework, it works by looking at the url and including the view in index.php as all the components necessary to this page.
So, as said the page was loading 3 times ( or making 3 entries on the database ), and I've stated digging my loading function, on wich I found a script that when a user is not activated it redirects to the home page. This header(location blah) was making the page load one extra time.
I've changed it to include home view and by now the page is only loading twice.
As far as I'm concerned I don't have any other redirect on the php scripts. I'll triple check but if not, I have to update this answer.
UPDATE -> at this point I'm having a strange situation here. I've run all my php and javascript code, and they are clean. I've finnaly discovered the bit of code that is giving me this problem, although it's a strange situation:
It seems that the bootstrap modal is giving me a redirect and I don't now why. I just have the html code at this point so I'm checking for javascript code on it and afterwards I'll look at bootstrap.js in order to find why this is happening.
I'll keep this thread updated !
UPDATE-> OK ! Now I have the full answer, it seems it wasn't bootstrap but an image I had. So I had this image called blahh that it's purpose was to preview an uploaded image, so, since the image didn't have a url defined, the it was redirecting ( the explanation is something like this lol ! I'm not even quite sure of what's happening here but giving the image an url I stopped having this error ).

Related

Why htaccess not working for mobile browser?

I have website (mzadkm.com) try to RewriteRule short url to app.php page .
So if user browse "mzadkm.com/app" will show "mzadkm.com/app.php" page
RewriteRule ^/app /app.php [L,R=301]
It's work on Computer , but on mobile browser give me 404 page
Any ideas
That probably is what you are looking for:
RewriteRule ^/?app /app.php [L]
The documentation clearly says, that the pattern in a RewriteRule get's applied to the relative path of the request if the rule is implemented inside a distributed configuration file. That means you actually want to match the path app and not /app here. Which is why your rule did not get applied. The ^/?app is a variant to accept both path notations, relative and absolut, which means the same rule can get implemented in the central configuration or likewise in a distributed configuration file (".htaccess").
I took the liberty to also remove the external redirection you showed ("R=301") since that most likely is not what you want, according to the phrasing of your question. Instead you want an internal rewrite .
You need to take care however that you do not implement a rewriting loop. Which would result in failing requests and an "internal server error" (http status 500).
One approach would be that:
RewriteEngine on
RewriteRule ^/?app$ /app.php [L]
Here another one:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?app /app.php [L]
Why things looked fine on your computer, but not on a mobile browser is unclear. Since the same rules get applied and the requests look the same there has to be another reason for that. I suspect you looked at a cached result of a previous attempt somewhere. Remember to always use a fresh anonymous browser window when testing. And to check the response you receive back inside your browsers network console.

Joomla - htaccess Redirects Error

I've had a Joomla 2.5.28 site for quite a while now and recently changed hosting providers. On the new server I managed to get Joomla updated to 3.2.7 and get it to run normally.
Now for the tricky part:
On my previous hoster I had a second installation being kind of the gateway to the other site. It just lets you select language and that's it.
My domain is www.cyclingtoserve.at with Joomla Main being /joomla and Joomla portal being /3.1
I figured by adding a REDIRECT rule from / to /3.1 I could get the portal up and running again. Sadly not.
This is what I get:
I thought I could undo this by deleting the .htaccess file. The problem lives on though.
I've tried just about everything. Help is VERY MUCH appreciated!
Edit01: A bit more info may be interesting.
The Joomla install is in /joomla while the other page is in /3.1
The .htaccess file however was in the root directory.
Edit02: I have managed to remove the wrong redirection. Question is: What is the correct way to redirect people from www.cyclingtoserve.at to /3.1? (without it showing up in the address)
Edit03: Here is a graphical representation (FTP) of the folder structure.
ftp
In order to avoid the redirect loop, you need to first check to see if your are already in the /3.1/ folder. Try this:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/3.1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ http://%{HTTP_HOST}/3.1/$1 [L,R]
Sadly I've had to give up using .htaccess for the redirection.
I would have loved the recommended way (and still would like to know how).
Solution:
index.html in root has the following lines:
<frameset rows="100%" frameborder=0 framespacing=0 border=0>
<frame src="http://cyclingtoserve.at/3.1/" name="Content" noresize>
<noframes>
It may be the quick and dirty way of dealing with this issue, but it works.
If you can reproduce the same results with .htaccess, I'd love to tag it as an answer.

Mod Rewrite to remove language from url in Concrete5 cms

I'm totally stumped. Hope you can help. I just spent a month redeveloping our website in Concrete5 version 7.3.1, latest version, and I'm ready to launch. It's a multi-lingual site and our SEO guy recommended not to include the language in the URL for the default language (English) as it would change our homepage from domain.com/ to domain.com/en/, and our old site default language was in the base directory.
Concrete5 doesn't support this so basically I'm hoping to accomplish this with some .htaccess trickery, but am getting no where.
Concrete5 urls are domain.com/index.php/en/path/to/page, so all pages are fed off index.php. There is a rewrite rule as follows to hide the index.php from the user and make the urls pretty.
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME}/index.html !-f
#RewriteCond %{REQUEST_FILENAME}/index.php !-f
#RewriteRule . index.php
I want to further add a way to add the /en/ for the server side from a url which doesn't include it. i.e.
RewriteRule ^/index.php/(.*) ^/index.php/en/$1 [L]
So I can then strip the en from the urls and the system will still work.
I've tried putting this before concrete's rewrite (without index.php), after, and multiple different combinations, but keep getting a 401 error and it's hard to diagnose the problem as it's not so easy to see the generated url.
Any help would be much appreciated as I've got to figure this out before launch.
With this recently added event in the new 5.7.4 version that is to come out sometime soon, we're able to do some interesting things with the request. One thing we can do is ensure the page at that path doesn't exist, then rewrite the request to make it look to concrete5 that the request is actually coming in to /en.
\Events::addListener('on_before_dispatch', function() {
$request = \Request::getInstance();
$page = \Page::getByPath($request->getPath()); // Get the real requested page
if ($page->isError()) { // If it doesn't exist
$path = new \Concrete\Core\Url\Components\Path($request->getPath());
$path = $path->prepend('en'); // prepend "/en" to the path, ex: "/path/to" becomes "/en/path/to"
$page = Page::getByPath($path);
if (!$page->isError) { // Make sure that this page actually exists
// This may not work, you might need to replace the actual \Request instance.
$request->setCurrentPage($page); // Set it to the requested page.
}
}
});
I really suggest that you do not do this. As described in my comments on the question, you'll run into really weird cases that will cause SEO issues and general routing issues in your site.
Edit: concrete5 version 8 includes HTTP middleware, which is a better solution to this problem.

.htaccess slug url

I'm wondering if anyone will be able to help me, I'm trying to make a site using slug URLs.
At the moment if a user sees the url it is something like
http://www.thedomain.com/artists-single.php?aid=123
but ideally I would like the URL to be
http://www.thedomain.com/artist/artist-name
.
I have in the database a url friendly artist name which I would like to use.
At the moment within my .htaccess file I have the following:
RewriteEngine On
RewriteBase /
RewriteRule ^artists-single\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
The site itself is written with PHP.
Thanks.
You can get Apache to access MySql and map "artist-name" to it's corresponding ID, see here (Thanks to #Marc B for the link). However, you could also do something like this though (this is what I personally use),
RewriteRule ^artist/([a-zA-Z0-9]+)/?$ /artist-single.php?artist=$1 [L]
Then in PHP use $_GET['artist'] to get the value, then query that against the database to get the artist's ID. Or you could use the ID, like
RewriteRule ^artist/([0-9]+)/?$ /artist-single.php?aid=$1 [L]
The URL would be like www.example.com/artist/123, which would pass the id to $_GET['aid']
I would recommend that you make use of a very simple Front Controller. This will give you the least headache and should be rather simple looking at your current setup. Have a quick peak at this for more details: http://www.technotaste.com/blog/simple-php-front-controller/
But just to give you a quick starting point, a Front Controller will be "the first part" that gets executed, traditionally this was the "index.php" file. Using this Front Controller you can then have SEO-friendly URLs and not change any core functionally to your other files.

net::ERR_INCOMPLETE_CHUNKED_ENCODING

I use .htaccess to rewrite url from someurl.com/ to someurl.com/public/. First .htaccess in www root contains this:
DirectoryIndex ./public/
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./public/$1 [QSA]
and second one in folder /public/ contains this:
DirectoryIndex _main.php
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^(.*)$ ./?params=$1 [QSA]
And the problem is when I open url someurl.com/ without "public". Page is loaded correctly, but in Google Chrome console I got error: net::ERR_INCOMPLETE_CHUNKED_ENCODING. When I open url someurl.com/public/ page loads without any error.
Any ideas, please?
In my case, the problem was cache-related and was happening when doing a CORS request.
I post my response here cause this is the first resource I found on Google for net::ERR_INCOMPLETE_CHUNKED_ENCODING error.
Forcing the response header Cache-Control to no-cache resolved my issue:
[ using Symfony HttpFoundation component ]
<?php
$response->headers->add(array(
'Cache-Control' => 'no-cache'
));
I had this issue when trying to access some parts of the WP admin area, I managed to resolve it by adding the below to my functions.php file;
add_filter('wp_headers', 'wpse167128_nocache');
function wpse167128_nocache($headers){
unset($headers['Cache-Control']);
return $headers;
}
We had net::ERR_INCOMPLETE_CHUNKED_ENCODING problem in case of HTML, which contained too much empty lines. Some browsers had difficulties with interpretation of long files.
Once we made applied code cleaning in our templates by cleaning code from empty lines, all was perfect.
I was also facing same issue. Finally i got this was the permission issue on cache folder.
I decided changing the file : /etc/apache2/mods-enabled/cgid.conf
Adding the following code snippet:
<IfModule mod_cgid.c>
CGIDScriptTimeout 60
</IfModule>
This problem is really general, in my case I deactivated the WP Super Cache plugin, and didn't get the bug anymore, but this is so general that no one can really help you because of different configurations of servers/wordpress
In my case, the problem was the Windows anti-virus software (Kaspersky). Turning it off, the problem was gone :/
For me it was the Zend PHP Opcache. It had reached its memory limit and could no longer cache all scripts. This was a problem for a massive code base like Magento 2.
Increasing the memory limit solved the issue after weeks of banging head on desk.
It is about server side problem.
The user has running web service does not right access to web server cache folder.
Make sure nginx user can write to /var/lib/nginx (or /var/cache/nginx in some distros).
Make sure nginx user can write to the folder (find the nginx user form nginx configuration file is located usually in /etc/nginx/nginx.conf)
Give the right access (chown -R nginx:nginx /var/lib/nginx/)
Reload the service(-service nginx reload -in centos)

Resources