I want to let my site http://subdomain.domain.com redirect to another external SSL-encrypted domain https://subdomain.external.com, while keeping the original address in the browsing bar. As far as I know, it is possible with CNAME to do this very easily, but the problem is that it redirects to the external link without SSL encryption.
I have been told that this can be done with .htaccess file, which right now has the following contents:
# 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
Can you help me know how should I modify the .htaccess file to meet my requirement? Thank you very much!
Juan
If you want to do it with PHP:
$redirect = "https://www.ssl.com".$_SERVER['REQUEST_URI'];
header("Location: $redirect");
exit;
Then you have to route all requests to this PHP file via .htaccess:
RewriteEngine on
RewriteRule ^([^.]+)$ index.php [QSA]
Related
My site is on wordpress.
This is the code I have written for hatccess file. But the redirection doesnot work. I want to force user redirect into www even if they donot write www inthe address bar. or click on a link which does not have www on it.
So I have added the following 301 redirection at the top of htacess file. but the redirection does not work. it only works with the home page. but not with the other pages. With the home page it works probably because I have set the site url = https://www.inetplc.com
Redirect 301 http://inetplc.com/ https://www.inetplc.com
Redirect 301 http://www.inetplc.com/ https://www.inetplc.com
Redirect 301 https://inetplc.com/ https://www.inetplc.com
Redirect 301 https://inetplc.com/case-studies https://www.inetplc.com/case-studies
Redirect 301 https://inetplc.com/about-inet https://www.inetplc.com/about-inet
I have tried configuring the lines like the following. but then the whole page is down. I dont know why.
Redirect 301 /about-inet https://www.inetplc.com/about-inet
This is the rest of the code in htaccess file.
#This Apache config file was created by Duplicator Installer on 2019-07-19 09:20:24.
#The original can be found in archived file with the name htaccess.orig
# 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 wrote the code to enable keep alive it also did not work . so I removed that .
# Keep Alive
<ifModule mod_headers.c>
Header set Connection keep-alive
</ifModule>
What I am doing wrong? Wordpress version 5.2.2
It seems you just need to redirect your website from http://inetplc.com or http://www.inetplc.com to https://www.inetplc.com
Add following code in your .htaccess to redirect https://www.inetplc.com
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^(.*)$ https://www.inetplc.com/$1 [R=301,L,NE]
# 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 would like to have a multilingual website but I haven't finished english version yet so I would like to redirect if url has /en/ to a specific page with a content "Soon". This page would be www.sitename.com/en/welcome
I am doing this in Wordpress and I don't know .htaccess that good. This code actually works pretty good, it checks for language set and redirects accordingly, but the problem is that after visiting that url I want to go to www.sitename.com, it still redirects me to that page (probably since locale doesn't change).
add_action("template_redirect", 'pl_redirect');
function pl_redirect() {
// if is english redirect to page id 193
if (get_locale() == 'en_US' && !is_page(193)){
wp_redirect( 'http://www.sitename.com/en/welcome' );
exit;
}
}
How can I accomplish the same thing correctly?
I tried this in .htaccess but it doesn't work
Options +FollowSymLinks
RewriteEngine on
Redirect 301 ^/en/$ /en/welcome
This is by Wordpress inside .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /web/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php [L]
RewriteRule ^/en/$ /en/welcome [R=301]
</IfModule>
Assuming you have actually installed everything in a directory called /web - you'll need 2 .htaccess files:
/.htaccess (the root WordPress .htaccess file)
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
# the base directory
RewriteBase /web/
# this means "don't rewrite /web/index.php"
RewriteRule ^index\.php$ - [L]
# this is a router any URL that's neither a file
# nor a directory will be routed to /web/index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /web/index.php [L]
</IfModule>
/web/.htaccess (your rewrite)
RewriteEngine On
RewriteRule ^en/?$ /web/en/welcome [NC,L,R=302]
I have a new WordPress site, example.com, with the old Drupal site archived at archive.example.org. Many files on the old site had a URL like so (ex: example.org/files/foo.pdf), but all those links out there in the internet are breaking because all those file downloads need to be redirected to archive.example.org/files/foo.pdf.
Can creating redirects (I'm guessing .htaccess is the best bet) work for file downloads as well? Is there a simple redirect to send all old links to the archive subdomain?
I have tried:
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/files/
RewriteRule ^ http://archive.example.org%{REQUEST_URI} [R,L]
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress
...with no luck so far.
Thanks for any help!
If you want to redirect all files/* requests to the new domain and keep everything else from WordPress, you need a condition for the rule, which checks for files
RewriteCond %{REQUEST_URI} ^/files/
RewriteRule ^ http://archive.example.com%{REQUEST_URI} [R,L]
When everything works as it should, you may replace R with R=301. Never test with R=301.
We have a site running on WordPress ada.localhost.com
Now all request to base url (http://ada.localhost.com/) have to go through tracking page (track.com/c/0912321323/?u=xxx) where u parameter is where to redirect user after he is tracked.
I've created a copy of index.php (index2.php) and I want to create htaccess rule to redirect all base url traffic to:
http://track.com/c/0912321323?u=http%3A%2F%2Fada.localhost.com%2Findex2.html (http://ada.localhost.com/index2.php)
Typical WP htaccess file looks like this
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
Any clue on how to set it up and if WordPress allow this configuration?
From what I found WordPress won't work with index2.php.
Solution for this is to write a plugin which deals with it.
I'm using a CakePHP framework on a shared hosting and cannot turn on URL rewriting.
The installation is in a folder called /tc. Everything works fine when I open /tc/index.php/Controller/Action.
However, I would like to make it a little easier for my users so that they do not have to open /tc/index.php but only /tc (which then should be redirected to /tc/index.php).
How do I do that with .htaccess?
Thank you!
Clarificaiton
I want a request on /tc/ to be redirected to /tc/index.php
SOLUTION
Worked for me with a simple
RewriteEngine On
RewriteRule ^$ index.php/$1 [L,QSA]
CakePHP handels the rest because all the links point to /tc/index.php/Controller.
Thanks for your help!
Try Using following code in .htaccess
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
IndexIgnore *
</IfModule>
try this :
1) open " mod_rewrite " from apache server.
2) comment " Configure::write('App.baseUrl', env('SCRIPT_NAME')); " this line from /confige/core.php
Below is the rule of .htaccess by which you can remove index.php from URL means if anyone enters http://example.com/index.php it redirects to http://example.com/.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /([^/]+/)*index.php HTTP/
RewriteRule ^(([^/]+/)*)index.php$ http://www.%{HTTP_HOST}/ [R=301,NS,L]
Above are the two rules by which you can redirect index.php to root directory.