$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>mod rewrite - How to write .htaccess so that https is on for subpages only but not the home page|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

mod rewrite - How to write .htaccess so that https is on for subpages only but not the home page

matteradmin10PV0评论

The root of my domain successfully redirects to a subdirectory, meaning example redirects to example/abc.

example has no WordPress install.

example/abc has its own WordPress install.

The homepage on is not HTTPS and I don't want it to be, however, I do want all the sub-pages to be HTTPS (eg. or )

My current .htaccess file is the standard WordPress stuff...

# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /abc/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /abc/index.php [L]
</IfModule>

# END WordPress

I've checked and tried many other solutions that I've found here but so far no joy.

p.s. I know to re-save permalinks after making changes like this to the .htaccess file.

The root of my domain successfully redirects to a subdirectory, meaning example redirects to example/abc.

example has no WordPress install.

example/abc has its own WordPress install.

The homepage on http://example/abc is not HTTPS and I don't want it to be, however, I do want all the sub-pages to be HTTPS (eg. https://example/abc/xyz or https://example/abc/thistoo)

My current .htaccess file is the standard WordPress stuff...

# BEGIN WordPress

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /abc/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /abc/index.php [L]
</IfModule>

# END WordPress

I've checked and tried many other solutions that I've found here but so far no joy.

p.s. I know to re-save permalinks after making changes like this to the .htaccess file.

Share Improve this question edited Oct 21, 2018 at 14:27 MrWhite 3,8911 gold badge20 silver badges23 bronze badges asked Oct 21, 2018 at 0:04 au_Martinau_Martin 233 bronze badges 1
  • "example redirects to example/abc" - where are you performing this redirect? "The homepage on http://example/abc" - presumably you mean http://example/abc/ (with a trailing slash)? – MrWhite Commented Oct 21, 2018 at 9:53
Add a comment  | 

1 Answer 1

Reset to default 1

Presumably your .htaccess file is located in the /abc subdirectory? In which case you can do something like the following to force HTTPS on all sub-pages, except the homepage:

This needs to go at the very top of your .htaccess file:

RewriteCond %{HTTPS} !on
RewriteRule !^(index\.php)?$ https://example%{REQUEST_URI} [R=302,L]

This assumes that the SSL cert is installed directly on your application server.

The negated RewriteRule pattern !^(index\.php)?$ only matches non-empty (or not index.php) URL-paths, so this excludes the homepage.

Change the 302 (temporary) to 301 (permanent) only when you are sure it's working OK, to avoid caching issues. Clear your browser cache before testing.


Aside:

RewriteBase /abc/
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /abc/index.php [L]

Since you have set the RewriteBase directive, you can remove the directory-prefix from the RewriteRule substitution (this is what the RewriteBase directive does):

RewriteRule . index.php [L]

However, since your .htaccess file is in the /abc subdirectory, then you don't actually need the RewriteBase directive or the directory-prefix.

Post a comment

comment list (0)

  1. No comments so far