Please give me a suggestion for my question.
when we set permalink in our site then the .htaccess code is
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
my site covert into http to https and i am adding below code to my .htaccess
RewriteRule ^index\.php$ - [L]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_FILENAME} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_FILENAME} [L,R=301]
These codes are to redirect when we using www or and http then automatically convert into https:
So my problem is when we add this code to my .htaccess the post name or permalink is not working.
home page was showing and also we can see the wp-admin pages, And all other links (example.www.xyz.com/register) not working.
What i do? Please give your valuable suggestions and answers.
Here is the correct syntax for your .htaccess - just replace domain.com with your actual website domain.
The first rewrite appends the www to all requests, the second rewrite appends the https to all requests.
Make sure to update your general settings in Wordpress as well, which you already commented that you did.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^domain.com
RewriteRule (.*) http://www.domain.com/$1 [R=301,L]
RewriteCond %{SERVER_PORT} !443
RewriteRule ^(.*)$ https://www.domain.com/$1 [r=301,nc,L]
Related
I need to redirect all traffic to both https and www on a WordPress site. I have gone through dozens of stackoverflow posts and feel like I finally found the answer here: htaccess redirect to https://www
I am using the code below in my htaccess file and it's somewhat working. The root domain inspiresoftware.com is redirecting to https://www.inspiresoftware.com. However if I go directly to a subpage ex. inspiresoftware.com/library, it redirects to the www version, but not the https version. What do I need to edit to make it do both? Thanks!
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule .* https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /q
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
I'm trying to convert my Wordpress site to HTTPS. I've mostly completed this now, but I would like to add 301 redirects to https. Every time I add the additional redirect code to my htaccess, my site falls over with 'too many redirects'.
This is my existing htaccess:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
I'm trying to merge the following redirects with the above:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^ukuleleclub.org [NC,OR]
RewriteCond %{HTTP_HOST} ^www.ukuleleclub.org [NC]
RewriteRule ^(.*)$ https://ukuleleclub.org/$1 [L,R=301,NC]
Can anyone help me achieve that?
Thank you :)
Your rule redirects www.yourSite.com to www.yourSite.com and it causes the Redirect loop. You need to check the %{HTTPS} variable to redirect non-https to https :
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R]
A friend of mine asked for help about his wordpress site. He did his work under sub.domain.com and now he'd like to have domain.com redirected to it, if possible without showing sub in the url bar
This is his domain root .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Following some resources I found, I inserted these two lines after the RewriteEngine On:
RewriteCond %{HTTP_HOST} ^sub\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R]
But it doesn't seem to work, it should be so simple but I am doing clearly something wrong...
I tried also commenting the rest, it didn't work
I am not an Apache expert at all, what's the problem?
To redirect example.com/ to sub.example.com/ ,you can use the following :
RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^$ http://sub.domain.com/$1 [L,R]
^$ matches the root / of example.com ,if you want to redirect everything to subdomain ,change the pattern to ^(.*)$ .
I have checked all of the related questions I can find in here (and in Google in general), and tried all of the various solutions given, but haven't been able to get this to work.
I am working on a Wordpress site that has recently gone SSL. I have set it up so that all pages are forced to https by adjusting the Settings page in the Admin area, adding the appropriate line to the wp-config file to force the admin side to be https and have modified my htaccess files to the following:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/branding/
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteRule ^branding/ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
Here's what I would like this to do...
1) http://www.example.com/ (and any sub pages except branding) gets redirected to https://example.com
2) http://example.com/branding stays as it is
3) https://example.com/branding is redirected to http://example.com/branding
The above htaccess code works to force the http: to https:, however, if I enter either http://example.com/branding or https://example.com/branding I am redirected to https://example.com.
I have used numerous variations of the initial Rewrite code and placed it in various places (as instructed in various other answers to similar questions here) with no change to the result.
If anyone can tell me where my error is and how to fix it, it would be much appreciated.
Try this:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/branding/
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteRule ^branding(.*) http://%{HTTP_HOST}/branding$1 [R=301,L]
With the help of a colleague, we got it worked out. Here's the updated code...
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/branding/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/branding/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
The WP-specific rules in the htaccess file cause some strange situations to occur. The main one being that there is an internal rewrite from /branding/ to /index.php, and then WP handles the request within the PHP. The file checks will handle the check to ensure that the index.php file exists. WP will internally deal with redirecting valid page requests that don't have trailing slashes.
Been searching for this for hours... Here is the tweak if you need to redirect more than one page to http from https.
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/page1|page2|page3/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} ^/page1|page2|page3/$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
For IP canonicalization, I'm told I need to redirect the IP address of the site to the domain name. I'm running a standard WordPress install that already comes with it's own .htaccess file. I modified it below by adding the "Redirect" line:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
Redirect 301 http://12.34.56.789 http://www.domainname.com
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
However, it's not working. Anyone know what is wrong?
Thanks!
You generally don't want to mix Redirect (mod_alias) with RewriteRule (mod_rewrite) because they both get applied to the same URI and will clobber each others changes sometimes. Just stick with mod_rewrite because you have wordpress rules that already use it.
Replace the
Redirect 301 http://12.34.56.789 http://www.domainname.com
with:
RewriteCond %{HTTP_HOST} ^12\.34\.56\.789$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
Jon Lin's answer worked for me but I had to use
RewriteCond %{REMOTE_ADDR} ^12\.34\.56\.789$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]
instead of
RewriteCond %{HTTP_HOST} ^12\.34\.56\.789$
RewriteRule ^(.*)$ http://www.domainname.com/$1 [L,R=301]