I can't make redirect from http to https :'(
My actual .htaccess looks like
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
</IfModule>
I'm adding next rows
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
But getting conflict with previous rows.
I put http://www.example.com/lents/johnson.html?type=1 to url.
And instead of getting same with https
I'm getting https://www.example.com/index.php?type=1
THANKS!
You need to put your redirect rules above all the others so the redirect occurs before any of the URL rewriting happens:
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* index.php [L]
Related
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
#RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
RewriteRule ^tags tags.php [L,NC]
</IfModule>
i want to add new page .but write page not found. why? please help me.
RewriteRule ^tags tags.php [L,NC] // i want this www.example.com/tags open tags.php ?
You need to reorder your htaccess rules like this :
DirectoryIndex index.php
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^(.*)//(.*)$
RewriteRule . %1/%2 [R=301,L]
RewriteRule ^tags/?$ tags.php [L,NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
</IfModule>
The problem is that, your rule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ index.php?qa-rewrite=$0&%{QUERY_STRING} [L]
Rewrites any request (not a true file/dir) to index.php. since /tags is not an existent file on your directory, so a request for http://example.com/tags was being rewritten to /index.php and the last rule(s) never executed.
I have pages with redirecting to www.homage.com/index.php.
It should be redirecting to the www version. here my Htaccess File:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
# Redirect non-www urls to www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.mindscopeproducts\.com
RewriteRule (.*) http://www.mindscopeproducts.com/$1 [R=301,L]
Have it this way:
Options +FollowSymLinks
RewriteEngine on
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# Redirect non-www urls to www
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http://www.mindscopeproducts.com%{REQUEST_URI} [R=301,L]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L]
i.e. keep external redirect rule before other forwarding rules. Make sure to clear your browser cache when testing this.
Reorder your rules like this :
<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
#Redirect non-www urls to www
RewriteCond %{HTTP_HOST} !^www\.mindscopeproducts\.com$
RewriteRule ^(.*)$ http://www.mindscopeproducts.com/$1 [R,L]
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
RewriteCond %{REQUEST_URI} !^/(media|skin|js)/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I know there are some questions like this out there but the solutions are not helpful for me.
I´m using htaccess to redirect to the index.php if the request file isn´t defined (code above).
I´d like to add a code-line that if the user requests for example:
http://www.example.com/test/index.php
he will redirect to
http://www.example.com/test/
but internal it will redirect to the index.php.
Is there a way to extend my code so that it works like I want it to?
# Add Slash
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
# Redirect to index.php if the following sites were not match
RewriteBase /
RewriteCond %{REQUEST_URI} \.(php|sql|tgz|gz|txt|ttf|TTF|log|txt|ini|html|xml|xhtml|htm)$
RewriteCond %{REQUEST_URI} !^/index.php$
RewriteCond %{REQUEST_URI} !^/phpinfo.php$
RewriteCond %{REQUEST_URI} !^/out.php$
RewriteCond %{REQUEST_URI} !^/sitemap[^0-9]*\.xml$
RewriteCond %{REQUEST_URI} !^/robots.txt$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !^/$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
Complete code:
DirectoryIndex index.php index.html
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# Take off index.php
RewriteCond %{REQUEST_URI} ^(.*/)index\.php$ [NC]
RewriteRule ^ http://%{HTTP_HOST}%1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} \.(php|sql|tgz|gz|txt|ttf|TTF|log|txt|ini|html|xml|xhtml|htm)$
RewriteCond %{REQUEST_URI} !^/((index|phpinfo|out)\.php|robots\.txt|sitemap[^0-9]*\.xml)$
RewriteRule ^(.*)$ /index.php?dir=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /index.php?dir=$1 [QSA,L]
# Add Slash for non-files
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]
I'm trying to exclude few URI from htaccess based redirection
My htaccess directives are bellow
<IfModule mod_rewrite.c>
RewriteEngine on
#
RewriteCond %{HTTP_HOST} ^(www\.)?domain1.com$ [NC]
RewriteRule !=/test$ http://domain2.com [L,R=301,NC]
#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
What wrong in this? Any suggesion?
I have tried in a different way as well
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !=/test
RewriteRule (.*) http://domain2.com? [R=301,L]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
While doing external redirection, exclusion of the the URI, test is not in effect. If I'm doing an internal rewrite, its working fine.
Maybe this works:
Options +FollowSymlinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_URI} !/test
# Add next line
RewriteCond %{REQUEST_URI} !index\.php [NC]
RewriteRule (.*) http://domain2.com? [R=301,L]
# Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !=/favicon.ico
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
</IfModule>
So far my .htaccess is like this:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
<FilesMatch "\.(htm|php|js|css|htc|png|gif|jpe?g|ico|xml|csv|txt|swf|flv|eot|woff|svg|ttf|pdf|gz)$">
RewriteEngine Off
</FilesMatch>
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .*\.html$ index.php [L]
I would like to have url with trailing slash redirected to the one without. But the slash for directories should be kept.
Any help would be very appreciated!
UPDATE:
after some more Google research i assembled some working solution for me. Both rewriting for removing trailing slash and redirect for www are working.
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTP_HOST} ^rudolfapotheke.de$ [NC]
RewriteRule ^(.*) http://www.%{HTTP_HOST}/$1 [L,R=301]
First, I would change your FilesMatch to a RewriteCond
RewriteCond %{REQUEST_FILENAME} !\.(?:htm|php|js|css|htc|png|gif|jpe?g|ico|xml|csv|txt|swf|flv|eot|woff|svg|ttf|pdf|gz)$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
and simplify the pattern for the next RewriteRule
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule \.html$ index.php [L]
or put the two rules together and test just for
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php [L]
and finally the rule for removing the trailing slash
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/$ $1 [R,L]
To redirect those with trailing slash, you need to check if the path is a directory with a RewriteCond and then include a RewriteRule if the filename matchs /$
So it would look something like this:
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ $1 [R=permanent,L]