Forum Moderators: phranque
RewriteCond %{HTTP_HOST} ^([a-zA-Z0-9]+)/?$ [NC]
RewriteRule ^(.*)$ https://example.com/sub-directory-parent/$1/index.php [L]
RewriteRule ^([a-zA-Z0-9]+)/?$ https://example.com/sub-directory-parent/$1/index.php [L]
RewriteRule ^([a-zA-Z0-9]+)/?$ https://example.com/sub-directory-parent/$1/index.php [L]
This does make the trailing slash optional (as you mention), however, in doing so you potentially have a duplicate content issue - do you really need that trailing slash?
RewriteRule ^([a-zA-Z0-9]+)/?$ https://example.com/sub-directory-parent/$1/index.php [L] RewriteRule ^([a-zA-Z0-9]+)$ https://example.com/sub-directory-parent/$1/index.php [L] you really want to externally redirect the noncanonical version(s) of the url to the canonical version and then only serve the internally rewritten content to the canonical url request.
do you really need that trailing slash?
192.168.199.1 - - [08/Sep/2016:23:05:04 +0100] [example.com/sid#7f42e437ee70][rid#7f42de5590a0/initial] (2) init rewrite engine with requested uri /x8b967d98/
192.168.199.1 - - [08/Sep/2016:23:05:04 +0100] [example.com/sid#7f42e437ee70][rid#7f42de5590a0/initial] (3) applying pattern '^(.*)$' to uri '/x8b967d98/'
192.168.199.1 - - [08/Sep/2016:23:05:04 +0100] [example.com/sid#7f42e437ee70][rid#7f42de5590a0/initial] (3) applying pattern '^([a-zA-Z0-9]+)$' to uri '/x8b967d98/'
192.168.199.1 - - [08/Sep/2016:23:05:04 +0100] [example.com/sid#7f42e437ee70][rid#7f42de5590a0/initial] (1) pass through /x8b967d98/
192.168.199.1 - - [08/Sep/2016:23:07:22 +0100] [example.com/sid#7f42e437ee70][rid#7f42de55b0a0/initial] (2) init rewrite engine with requested uri /x8b967d98
192.168.199.1 - - [08/Sep/2016:23:07:22 +0100] [example.com/sid#7f42e437ee70][rid#7f42de55b0a0/initial] (3) applying pattern '^(.*)$' to uri '/x8b967d98'
192.168.199.1 - - [08/Sep/2016:23:07:22 +0100] [example.com/sid#7f42e437ee70][rid#7f42de55b0a0/initial] (3) applying pattern '^([a-zA-Z0-9]+)$' to uri '/x8b967d98'
192.168.199.1 - - [08/Sep/2016:23:07:22 +0100] [example.com/sid#7f42e437ee70][rid#7f42de55b0a0/initial] (1) pass through /x8b967d98
RewriteRule ^([a-zA-Z0-9]+)/?$ https://example.com/sub-directory-parent/$1/index.php [L]
My current design in my Apache config is:-
RewriteRule ^/([a-zA-Z0-9]+)/?$ /sub-directory-parent/$1/index.php [L]
RewriteRule ^/([a-zA-Z0-9]+)/?$ http://example.com/sub-directory-parent/$1/index.php [R=302,L]
RewriteRule ^/([a-zA-Z0-9]+)/?$ /sub-directory-parent/$1/index.php [L] What is the canonical URL?
From a product point of view I think it'd have to be with the slash.
RewriteRule ^/([a-zA-Z0-9]+)$ /$1/ [R=301,L]
RewriteRule ^/([a-zA-Z0-9]+)/$ /sub-directory-parent/$1/index.php [L]