Am rather new to this world of htaccess redirects.Am trying to force all redirects in my Zend MVC to my https but I get a requested URL not found error on requests that dont go though the index controller
Example
https://www.example.com/auth/register
gives a requested URL /auth/register not found error. However if I remove the https redirect rule it works fine over http. If I adjust the URL to
https://www.example.com/index.php/auth/register
it works fine.
The URL
https://www.example.com/index/faq
works just fine since it goes through the index controller.
My .htaccess file looks like this
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
What do I need to adjust to get the URL
https://www.example.com/auth/register
working?
Your code reads as "If this matches a file, link, or directory, then do nothing and continue." You need to skip the final rewrite rule in the case the file actually exists:
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [S=1,NC,L]
RewriteRule ^.*$ index.php [NC,L]
Related
I have .htaccess:
Options +FollowSymLinks
RewriteEngine on
RewriteRule cache/ - [F]
Options -Indexes
RewriteCond %{HTTP_HOST} ^www.domains.eu [NC]
RewriteRule ^(.*)$ https://domains.eu/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([a-zA-Z0-9\-\_\/]*)$ index.php?p=$1
# Blokada hotlinking czyli kradzieży obrazków
RewriteCond %{HTTP_REFERER} !^https://(.+\.)?domains.pl/ [NC]
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !google\. [NC]
RewriteCond %{HTTP_REFERER} !yahoo\. [NC]
#RewriteRule .*\.(jpe?g|jpg|gif|bmp|png|jpeg)$ - [F]
#AuthType Basic
#AuthName "Password Protected Area"
#AuthUserFile /home/webplay/domains/domains.eu/public_html/.htpasswd
#Require valid-user
# Prevent viewing of htaccess file.
<Files .htaccess>
order allow,deny
deny from all
</Files>
RedirectMatch 403 ^.*/apps/(.*).php(.*)$
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl|map)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
I need the following redirection::
redirect from http ://domains .pl, http ://www.domains .pl, https ://www.domains .pl, https ://domains .pl to https ://domains .eu
redirect from https ://www.domains .eu, http ://www.domains .pl, http ://domains .eu, to https ://domains .eu
Could I ask for help from my .htaccess made into these redirects?
will you please add below code and test it?
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://domains.eu/$1 [L,R=301]
Whit this code, the 404 redirect doesnt work. I dont get any error. If i type in an url that doesnt exists, i only get an empty white page.
Code updated:
<IfModule mod_rewrite.c>
RewriteBase /
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ htaccess.php?q=$1 [QSA]
</IfModule>
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
#RewriteEngine On
#RewriteCond %{HTTPS} !=on
#RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
#RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
#RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
RewriteEngine On
RewriteBase /
ErrorDocument 404 404.php/
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ 404.php [L]
Change ErrorDocument 404 /index.php to
RewriteEngine On
RewriteBase /
ErrorDocument 404 http://yourdomain.com/404.php/
RewriteCond %{REQUEST_URI} ^/404/$
RewriteRule ^(.*)$ /path/to/404.php [L]
The Rewrite rules map that URL to your 404.php script.
See this link for more information: http://httpd.apache.org/docs/current/mod/core.html#errordocument
I'm trying to force HTTPS through .htaccess and I'm constantly getting an error of too many redirects.
This is my .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^patrickwhitehouse.pw$ [NC]
RewriteRule ^(.*)$ http://patrickwhitehouse.pw/$1 [L,R=301]
#force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Options +MultiViews
<ifModule mod_gzip.c>
mod_gzip_on Yes
mod_gzip_dechunk Yes
mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
mod_gzip_item_include handler ^cgi-script$
mod_gzip_item_include mime ^text/.*
mod_gzip_item_include mime ^application/x-javascript.*
mod_gzip_item_exclude mime ^image/.*
mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</ifModule>
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^&\ ]+).html
RewriteRule .* /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.html [L]
RedirectMatch ^/blogs$ http://www.patrickwhitehouse.pw/blog.html
Your first rewrite rule is the culprit, for each successful redirection to https it then re-redirects to the hard coded http again on the next request after the external redirection...
Try this slightly modified version instead:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^patrickwhitehouse.pw$ [NC]
RewriteRule ^(.*)$ %{REQUEST_SCHEME}://patrickwhitehouse.pw/$1 [L,R=301]
#force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Or, a bit cleaned up:
RewriteEngine On
# force host 'patrickwhitehouse.pw'
RewriteCond %{HTTP_HOST} !^patrickwhitehouse.pw$ [NC]
RewriteRule ^ %{REQUEST_SCHEME}://patrickwhitehouse.pw%{REQUEST_URI} [L,R=301]
# force SSL
RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
I used next .htaccess code:
RewriteEngine on
# if the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule ^(.*)$ index.php/$1 [L]
It work nice, but it's available all pages with index.php and without it, for example:
http://localhost/framework/about
http://localhost/framework/index.php/about // need redirect to http://localhost/framework/about
I want to redirect all request with index.php to without index.php with SEO reasons, How can I remove index.php?
Try this
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/([^/]+)/index\.php/(.+)\s [NC]
RewriteRule ^.*$ /%1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
%{THE_REQUEST} contains the full HTTP request line sent by the
browser to the server (e.g., GET /index.html HTTP/1.1)
The condition RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/([^/]+)/index\.php/(.+)\s
[NC] matches something like GET /xxx/index.php/yyyy where xxx would be framework and yyy would be about/something/what/you/want or just about if you
want (could be also POST or another instead of GET but it does not really matter here).
Example: /framework/index.php/everything/about/me will be redirected to /framework/everything/about/me or /framework/index.php/about will be redirected to /framework/about
Pretty sure the following will redirect everything to the $_SERVER['PATH_INFO'] var in index.php
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !.index.ph.*
RewriteRule ^(.*)$ /index.php
It has been a while since I've used this method.
Alternatively you can use ForceType like this:
<Files *>
ForceType application/x-httpd-php
</Files>
<Files *\.*>
ForceType None
</Files>
This will allow you to have a PHP file called about (no extension) and have it executed as PHP.
I'm trying to remove the index.php from my CI urls, but having followed the instructions it doesn't seem to be working.
I have a codeigniter installation running in a subdirectory. There is a default controller set in the routes config called main, and another controller called 'create'. The default runs fine, but going to /create returns a 324 error saying No Data Received. My htaccess looks like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^system.*
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>
This should be enough:
<IfModule mod_rewrite.c>
RewriteEngine On
#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
#This last condition enables access to the images and css folders, and the robots.txt file
RewriteCond $1 !^(index\.php|public|images|robots\.txt|css)
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
This is what I use. My CodeIgniter also runs in a subdir.
RewriteEngine on
RewriteCond $1 !^(index\.php|images|swf|uploads|js|css|robots\.txt)
RewriteRule ^(.*)$ /ci/index.php/$1 [L]
.htaccess add:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
Go into application/config/config.php and clear the index page config value:
// Old
$config['index_page'] = "index.php";
// New
$config['index_page'] = "";
Solved My problem hope others too... :)
Sometimes you need to enable it the rewrite module, run "apache2 enable module rewrite":
sudo a2enmod rewrite
You need to restart the webserver to apply the changes:
sudo service apache2 restart
Then folow Sofia's answer.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
for ubuntu