I have done all the said solutions to remove 'index.php' from the URI. The procedure I took is as below:
In .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
In config.php
the base_url is set to
$config['base_url'] = 'https://trawellmate.com/';
Removed index.php from
$config['index_page'] = '';
These are the suggested solutions. But nothing worked. I am using SSL and all non requests are redirected to https://trawellmate.com. Following is the lines added to achieve in .htaccess:
#FORCE NON-WWW REDIRECT
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]
Earlier with non SSL(in development mode in localhost) it was working fine. Since, we are about to go live, a quick help will be deeply appreciated.
You may try to use the following rules. It worked for me.
RewriteEngine On
RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^www\. [OR]
RewriteCond %{HTTP_HOST} ^yourwebsite\.com$ [NC]
RewriteRule ^ https://www.yourwebsite.com%{REQUEST_URI} [R=301,L,NE]
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index\.php(/[^\ ]*)?\ HTTP/
RewriteRule ^index\.php(/(.*))?$ yourwebsite.com/$2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Allow overriding htaccess in Apache Configuration (Command)
sudo nano /etc/apache2/apache2.conf
and edit the file & change to
AllowOverride All
Below .htaccess configuration works for me
RewriteEngine on
RewriteBase /<app_directory>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /<app_directory>/index.php/$1 [L]
I've placed the .htacess file in /var/www/html ie. Parallel to application directory
Hope you have enabled mod_rewrite module for apache, Also add below block in virtualhost file(000-default.conf) of apache. Please restart server after changes.
<Directory /var/www/>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
Related
So I am quite new to codeigniter and I have been trying to get my head around removing the index.php from my local site, I have managed to make it work for the homepage after looking through other similar questions on SO but none have got it fully working. Whenever I visit another page on my site it displays the wamp page on my screen. Here is my code in codeigniter/.htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
# !IMPORTANT! Set your RewriteBase here and don't forget trailing and leading
# slashes.
# If your page resides at
# http://www.example.com/mypage/test1
# then use
# RewriteBase /mypage/test1/
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
# If we don't have mod_rewrite installed, all 404's
# can be sent to index.php, and everything works as normal.
# Submitted by: ElliotHaughin
ErrorDocument 404 /index.php
</IfModule>
I have also put in my apache/conf/httpd.conf
<Directory />
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
But still no luck, is there something I've missed? Thanks in advance
Follow the following step:
1. Change the config file like this:
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
2.Use the following .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
Note: .htaccess vary depending on server. I some server (e.g.: Godaddy) need to use the following .htaccess:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L,QSA]
Use this .htaccess works on most servers
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
# RewriteCond %{HTTPS} off
# RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
You can uncomment the last 2 lines to force HTTPS.
Also this could also work
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /foldername/
RewriteCond %{REQUEST_URI} ^system.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_URI} ^application.*
RewriteRule ^(.*)$ /index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule>
Note line 3 of the 2nd .htaccess RewriteBase /foldername/ use this RewriteBase / if your script can be reached without including a folder name.
I have my own CMS system, but I can't make a code in .htaccess file.
I want redirect from http://example.com/?page=forum to http://example.com/forum...
I don't know, how do it...
I tried the following:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /projects/cms/
RewriteCond ?page=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php [L]
But it didn't work.
Sorry for my bad English, thanks for Code.
The comment splash58 posted is correct - you need to check the QUERY_STRING for the presence of page=<something>, like this:
RewriteCond %{QUERY_STRING} page=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L,NE]
Your file should now look like this:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /projects/cms/
RewriteCond %{QUERY_STRING} page=([^\s&]+) [NC]
RewriteRule ^ %1? [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L]
If it is still not working, then you need to ensure that mod_rewrite is enabled on your server, and that AllowOverride All is set in your server or virtual host configuration. See this for more information on how to do so: http://tildemark.com/enable-htaccess-on-apache/
I'm very new to coding in general so please forgive me for my ignorance in the subject. I understand that their is a few questions similar to this, but none have seemed to work for me. Useful information is always welcome please due you're best to explain everything to me even if it seems a bit excessive because I'm fairly uneducated in theses particular subjects.
Here is my entire htaccess file located in my root forum directory.
RewriteOptions inherit
RewriteEngine on
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /forums/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpeg|jpg|gif|png)$ /forums/public/404.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forums/index.php [L]
</IfModule>
<Files 403.shtml>
order allow,deny
allow from all
</Files>
RewriteCond %{HTTP_HOST} ^perspectiverp\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.perspectiverp\.com$
RewriteRule ^home$ "https\:\/\/www\.perspectiverp\.com\/forums\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^perspectiverp\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.perspectiverp\.com$
RewriteRule ^Home$ "https\:\/\/www\.perspectiverp\.com\/forums\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^perspectiverp\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.perspectiverp\.com$
RewriteRule ^/?$ "https\:\/\/www\.perspectiverp\.com\/forums\/" [R=301,L]
My site will always connect to the website through https:// unless it is being directly told to do otherwise e.g. http://perspectiverp.com/forums/. My issue is that as my general connection is being directed through https:// users can still connect through http:// which is a major security flaw. I basically need it to be similar to how google has their system to automatically redirect http:// to https:// even if the user attempts to change it in the web address
e.g. http:/ww.google.com/ gets redirected to https:/ww.google.com/?gws_rd=ssl if the user attempts to change it to*http:/ww.google.com/.
As for anyone wanting to know what the forum software is, I'm currently using a Licensed version of Invision Powers Community Suit.
// UPDATED
First attempt Result was "Webpage has Redirect Loop"
RewriteOptions inherit
RewriteEngine on
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /forums/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpeg|jpg|gif|png)$ /forums/public/404.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forums/index.php [L]
</IfModule>
<Files 403.shtml>
order allow,deny
allow from all
</Files>
RewriteCond %{HTTPS} =off
RewriteRule ^ https://www.perspectiverp.com%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} ^(www\.)?perspectiverp\.com$ [NC]
RewriteRule ^(home)?$ https://www.perspectiverp.com/forums/ [R=301,NC,L]
Second attempt Result was "Webpage has Redirect Loop"
RewriteOptions inherit
RewriteEngine on
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /forums/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpeg|jpg|gif|png)$ /forums/public/404.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forums/index.php [L]
</IfModule>
<Files 403.shtml>
order allow,deny
allow from all
</Files>
RewriteCond %{HTTPS} =off
RewriteRule ^ https://www.perspectiverp.com%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} ^(www\.)?perspectiverp\.com$ [NC]
RewriteRule ^home$ https://www.perspectiverp.com/forums/ [R=301,NC,L
Third attempt Result was "Webpage has Redirect Loop"
RewriteOptions inherit
RewriteEngine on
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /forums/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.(jpeg|jpg|gif|png)$ /forums/public/404.php [NC,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /forums/index.php [L]
</IfModule>
<Files 403.shtml>
order allow,deny
allow from all
</Files>
RewriteCond %{HTTPS} =off
RewriteRule ^ https://www.perspectiverp.com%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} ^perspectiverp\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.perspectiverp\.com$
RewriteRule ^home$ "https\:\/\/www\.perspectiverp\.com\/forums\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^perspectiverp\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.perspectiverp\.com$
RewriteRule ^Home$ "https\:\/\/www\.perspectiverp\.com\/forums\/" [R=301,L]
RewriteCond %{HTTP_HOST} ^perspectiverp\.com$ [OR]
RewriteCond %{HTTP_HOST} ^www\.perspectiverp\.com$
Add the following just before your last three https:// rewrite rules.
RewriteCond %{HTTPS} =off
RewriteRule ^ https://www.perspectiverp.com%{REQUEST_URI} [R,L]
Once everything works as expected change R to R=301 above. Also, notice how the URL in my rewrite rule does not quote and escape any forward slashes as it isn't required.
You can also replace your last three rules with just this one:
RewriteCond %{HTTP_HOST} ^(www\.)?perspectiverp\.com$ [NC]
RewriteRule ^(home)?$ https://www.perspectiverp.com/forums/ [R=301,NC,L]
The NC flag makes the rule case-insensitive so home and Home both will match. The ? makes the preceding group () optional; so the RewriteCond works with both www and without it, and the RewriteRule matches on / as well.
I forced https:// through a reverse proxy server (Cloudflare) and was able to force my website to accept https:// traffic only.
I'm trying to set a site live. The site works perfectly fine on a live dev server which we've been using to show the site to the client. Here is the htaccess from the live dev (works fine):
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
#RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Rewrite to 'public' folder
RewriteCond %{HTTP_HOST} ^livedev.domain.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) public/$1 [L]
</IfModule>
AuthType Basic
AuthName "dev16"
AuthUserFile "/home/site/.htpasswds/public_html/passwd"
require valid-user
And here's the .htaccess from the live site:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
#RewriteCond %{HTTPS} !=on
#RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
#RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Rewrite to 'public' folder
RewriteCond %{HTTP_HOST} ^livesite.co.uk$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) public/$1 [L]
</IfModule>
The 2 are identical except for the HTTP_HOST and the removal of the authentication.
It gives me a generic "Internal Server Error".
I have tried deleting the contents of .htaccess which just gives me page not found so the issue definitely lies in .htaccess.
A total .htaccess virgin, what steps can I take to find the cause of the issue?
Thanks
(It's Laravel 3.2.13)
Use at same level of /public
This way first redirect to public
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [NC,OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteCond %{REQUEST_URI} !public/
RewriteRule (.*) /public/$1 [L]
And inside /public
then, you handle index.php
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I had exactly same setup as RamiroRS answer, but still got Internal Server Error. My problem was in file permissions. Folders should be 0755 and files 0644.
As an experienced web developer, I feel like an idiot posting this. Somehow I tend to have issues with .htaccess. I'm trying to route all requests within /wiki to my index.php with the following...
RewriteEngine On
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ./ /index.php [L]
Virutal host:
<VirtualHost *:80>
ServerName mysite.local
DocumentRoot "/var/www/mysite/public_html"
<Directory "/var/www/mysite/public_html">
Options Indexes FollowSymLinks MultiViews
AllowOverride All
Order allow,deny
allow from all
</Directory>
</VirtualHost>
I'm trying to access http://mysite.local/wiki/asdf and getting a 404 error.
Apache's error log shows nothing
If /wiki is an existing folder in your public_html root folder, and your index.php file is in the wiki folder, then you can give the following a try:
RewriteEngine On
RewriteBase /wiki
RewriteRule index\.php - [F,L]
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule .* index.php [L]
If the wiki folder does not exist, and you're doing all the work at the root:
RewriteEngine On
RewriteBase /
RewriteRule index\.php - [F,L]
RewriteCond %{REQUEST_URI} !-f
RewriteCond %{REQUEST_URI} !-d
RewriteRule wiki/(.*) index.php/$1 [L]
Now give this a try! To rewrite non-existence /wiki and /wiki/ and /wiki/$var into /index.php:
RewriteCond %{REQUEST_URI} ^/wiki/?
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) /index.php
I ended up needing what the Yii Framework uses...
RewriteEngine On
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php