I was gonna redirect non-www to www and copied this on .htaccess
# Generated by esoTalk
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ htts://www.domain.com/$1 [R=301,L]
</IfModule>
But Instead of https I write htts by mistake. And another mistake is I sent it instead inside directory of public_html,to upper root directory. And It's just gone. I can't find with find -name "*." command or I can't delete it on the root doing rm .htaccess Basically I can't access it but It broke the site I got ERR_TO_MANY_REDIRECTS on the non-www urls.
What I done in order to solve this:
Restarted apache
rebooted the vps
sending another .htaccess file to root which has correct https line
Nothing changed even I send a new same named .htaccess file the error didn't change still got a problem because of "htts"
Information:
Server version: Apache/2.4.10
Distro: Debian 8
Check for any .htaccess files with
find /your/web/root -name ".htaccess" -print
Then have just one .htaccess file, or a virtual host config, that performs HTTPS and domain checks first. Having a condition for %{HTTPS} should prevent your infinite redirects because it will skip the action when the request is already being handled over HTTPS.
RewriteEngine On
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} !^www\.domain\.com [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
Related
I have set up the DNS Zone of my domain towards the IP of my VPS.
When I type exemple.com I reach the httpdocs folder (the root folder) of the vhost wanted.
However in this folder there are few dirctories
httpdocs
-subfolder1
-Ssub-folder
-subfolder2
I would like :
1) that any request directed toward exemple.com be redirected toward exemple.com/subfolder1/ or idealy exemple.com/subfolder1/Ssubfolder/
2) and that the url displayed remains exemple.com
3) moreover, I also want to be able to acces to subfolder2 while typing exemple.com/subfolder2 or while typing my-IP-adresse/subfolder2
I made myself sure that the apache2.conf file contains AllowOverride All, and tried to edit the .htaccess file located in the httpdocs folder in many many ways, for instance :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^exemple\.com$
RewriteRule (.*) http://www.exemple.com/$1 [R=301,L]
RewriteRule ^$ /subfolder1 [L,R=301]
or
Options +FollowSymLinks
RewriteEngine on
RewriteRule !^subfolder1($|/) http://exemple.com/subfolder1/index.php/$1 [R=301,L]
Both redirect me correctly, but the url displayed is exemple.com/subfolder/
I've also tried
RewriteEngine on
RewriteRule (.*) http://exemple.com/subfolder/$1 [QSA,R=301,L]
But my url becomes http://exemple.com/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/subfolder1/
When I try this
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_URI} !^/subfolder1/
RewriteCond %{HTTP_HOST} ^(www\.)?exemple\.
RewriteRule ^(.*)$ /subfolder/$1 [L]
the server replies file not found
Finally I've tried
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www.)?exemple.com$
RewriteCond %{REQUEST_URI} !^/subfolder1/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /subfolder1/$1
RewriteCond %{HTTP_HOST} ^(www.)?exemple.com$
RewriteRule ^(/)?$ subfolder1/index.php [L]
but no redirection occurs
With more and more tries, I get similar results, but never the one aimed.
Any help would be awesome
Thank's in advance
ps: I'm on ubuntu 14.04.4 LTS and apache 2.4.7
This is driving me bananas. For some reason my domain will not work to redirect https-WWW to https-non-WWW. This works with every other permutation except https://www.nextoronto.com
What code do I use in the .htaccess that will allow it to work for all permutations?
Edit: This is the rewrite code now:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.nextoronto\.com [NC]
RewriteRule ^(.*)$ https://nextoronto.com/$1 [L,R=301]
It looks sound, perhaps that rule isn't being reached due to other rules in front of it?
Here is what I use that works:
# Force SSL
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://nextoronto.com/$1 [R=301,L]
# Redirect www to non-www
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^(.*)$ https://nextoronto.com/$1 [R=301,L]
# My other rewrites for routing all requests to index.php go here...
Edit the URL and try with this code:
RewriteEngine on
rewritecond %{http_host} ^www\.example\.com [nc]
rewriteCond %{SERVER_PORT} 80
rewriterule ^(.*)$ https://example.com/$1 [r=301,nc]
Step 1
You should make .htaccess file like this
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?url=$1
Step 2
Go to the directory, then view mark the option file extension. Then see the .htaccess file.
When no rewrite works, no matter what you do, consider what happened to me. IIS or WAMP, on my laptop, redirected all calls to my domain (call it example.com) to localhost. So creating all the rewrites on my example.com server were to no avail because no calls to example.com ever made it out of my computer. Just do a "ping example.com" and if you get an IP of 127.0.0.1, edit your HOSTS file.
Looked on here at all the answers regarding this issue but none fixes my issue. I have a directory called pdfs which used to contain all my .pdf files. They are now all inside pdfs/sales so trying to create a redirect for all files in the pdfs directory to look inside the pdfs/sales directory instead using a .htaccess file in the root of my site. Everything I've tried so far results in an infinite loop. Here's what my .htaccess looks like so far:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
RewriteRule ^pdfs/(.*)$ /pdfs/sales/$1 [R,NC,L]
RewriteRule ^(.*)$ /index.php?/$1 [L]
The first rule redirects all www. traffic to non-www. url. The second rule is my pdfs rule. The last rule is for redirecting all requests to index.php for seo friendly urls. Is there a conflict here? Where am I going wrong?
Thanks
You can keep your rule like this (my comment inline):
DirectoryIndex index.php
RewriteEngine on
# remove www from domain name
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
# redirect /pdfs/abc.pdf to /pdfs/sales/abc.pdf
RewriteRule ^pdfs/((?!(?:sales|rent)/).*)$ /pdfs/sales/$1 [R=302,NC,L]
# for all non-files and no-directories route to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?/$1 [L]
Make sure to test it after clearing your browser cache.
I'm trying to remove the ".php" extension from the URLs of a site using this code (which I admit I copy/pasted from other questions here) in the .htaccess file:
RewriteEngine on
Options +FollowSymLinks
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Other lines of the .htaccess file do work, for instance, I have an error redirect and:
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
So, I know the .htaccess file is in service in general.
I don't know what could go wrong in this area, so I'm not sure where to begin troubleshooting. Does anyone have pointers?
Thanks in advance.
Given that your domain account is /home/youraccount/public_html, your .htaccess would be inside the public_html folder with the following content:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /
# First we redirect the www to non-www
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^/?(.*)$ http://domain.com/$1 [R=301,L]
# now we redirect phpless URLs internally to the php
# if folder does not exist
RewriteCond %{REQUEST_FILENAME} !-d
# but the file exists and ends with .php
RewriteCond %{REQUEST_FILENAME}\.php -f
# redirect to name.php
RewriteRule ^([^/]+)/?$ $1.php [L]
NOTE: If you have more rules this may conflict so I would have to look at the rest of your rule but basically the above should work as expected.
You will be able to access both:
domain.com/index
and
domain.com/index/
And it would redirect to your file index.php.
I have installed ubuntu 12.04 and I have complete requirements(apache,mysql and php5) for running php projects. Projects which are not in codeigniter are working well. Within codeigniter , when I load the project the default controller loads the index_view but when I click to other controllers; they wont work with error and display error
Not Found The requested URL /academic/login was not found on this server.
I realized that the .htaccess wont work; then the /etc/apache2/httpd.conf file is empty
I would like to request a sample of basic configuration of httpd.conf file so that my htaccess file can work. If any suggestion that can help me to arrive at some results would be appreciated. Thanks.
My httaccess is given below
RewriteEngine On
RewriteBase /
### Canonicalize codeigniter URLs
# If your default controller is something other than
# "welcome" you should probably change this
RewriteRule ^(platform(/index)?)/?$ / [L,R=301]
RewriteRule ^(.*)/index/?$ $1 [L,R=301]
# Removes trailing slashes (prevents SEO duplicate content issues)
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ $1 [L,R=301]
# Enforce www
# If you have subdomains, you can add them to
# the list using the "|" (OR) regex operator
RewriteCond %{HTTP_HOST} !^(localhost|academic) [NC]
RewriteRule ^(.*)$ http://localhost/academic/$1 [L,R=301]
# Enforce NO www
#RewriteCond %{HTTP_HOST} ^www [NC]
#RewriteRule ^(.*)$ http://domain.tld/$1 [L,R=301]
###
# Removes access to the system folder by users.
# Additionally this will allow you to create a System.php controller,
# previously this would not have been possible.
# 'system' can be replaced if you have renamed your system folder.
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php/$1 [L]
# Checks to see if the user is attempting to access a valid file,
# such as an image or css document, if this isn't true it sends the
# request to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
# Without mod_rewrite, route 404's to the front controller
ErrorDocument 404 /index.php
This trusty one has never done me wrong:
RewriteEngine On
RewriteBase /academic/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/ [L]
ErrorDocument 404 /index.php