I want to forward request like this
http://www.website.com/ > https://www.website.com/ > https://website.com/
My .htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Try :
RewriteCond %{HTTP_HOST} !^website\.com$
RewriteRule ^ https://domain\.com [R=301,L]
Based on your shown samples, try. Please make sure you clear your browser cache before testing your URLs. Make sure you are placing your https rule at the top of your htaccess file.
<IfModule mod_rewrite.c>
RewriteEngine ON
RewriteBase /
RewriteCond %{HTTP_HOST} ^(?:www\.)(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [NE,R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Related
I have to redirect some url .
for example if the url is
www.example.com/shop valid
www.example.com/shop/red-product need redirection to www.example.com/red-product
www.example.com/shop/green need redirection to www.example.com/green
www.example.com/shop/any-string need redirection to www.example.com/any-string
How i can do this . Please help .
My current htacess file is
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Redirect 301 /bio/ https://www.example.com/bio/
Options -Indexes
You may replace your code with this one:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteRule ^shop/(.+)$ /$1 [L,NC,NE,R=301]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Below rule should work we are matching the group after shop only.
RewriteEngine On
RewriteCond %{REQUEST_URI} ^/shop/(.*)
RewriteRule ^ http://www.example.com/%1 [R]
I would like to force https connection through .htaccess in apache for vue.js history:
Vue history requires .htaccess like this:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
How can I modify this .htaccess to force SSL connection?
Line 3 and 4 are for redirecting to https.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
It is an old question but this what I'm using to force ssl in vue
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
How do I make a redirect from all pages following /react-api, such as:
www.example.com/react-api/workout?id=123
www.example.com/react-api/another-site/?id=321
to:
app.example.com/react-api
and I wan't to keep the folder and parameters.
This is what I have tried:
# 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]
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$
RewriteRule ^react-api/(.*) app.example.com/$1 [R=301,L]
</IfModule>
# END WordPress
But it doesn't work.
Please help
You need to use http:// in your target URL and also change order of your rules and keep redirect rule at the top:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com$ [NC]
RewriteRule ^react-api(/.*)?$ http://app.example.com%{REQUEST_URI} [R=301,NE,NC,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
So I'm trying to redirect incoming connections based on the referrer URL. So for instance if someone was trying to visit:
blog.example.com/category/fancy-stuff
They are already getting redirected to example.com but I want to redirect them to:
example.com/news/category/fancy-stuff
Right now I have this for my htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_REFERRER} blog.example.com/category/* [NC]
RewriteRule ^ example.com/news/category/*? [R=301,L]
</IfModule>
Is there a way to use variables or something to just append the proper category to the new URL?
Reorder your Rewrite rules :
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_REFERRER} ^blog.example.com/category/.*$ [NC]
RewriteRule ^(.*)$ http://example.com/news/$1 [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
How can I change my URL from domain.com/sprekers/?spreker=value to domain.com/value with a rewrite rule with wordpress.
I've tried to change it like this
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
than I tested it with the htaccess tester http://htaccess.madewithlove.be If I test it on the tester everything works fine but when I do this on my wordpress site it doesn't work. This is my complete htaccess file:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
</IfModule>
I think it doesn't work because the /sprekers is already "made" by wordpress how can I fix this?
Cheers
Robin
I think, you need to put your first code after the RewriteBase / rule.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} ^spreker=(.*)$
RewriteRule ^sprekers/$ %1/? [R=301,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>