Redirect destination is different depending on the presence or absence of a trailing slash.

Asked 2 years ago, Updated 2 years ago, 59 views

I am trying to redirect it by writing it in .htaccess.
The directory configuration is as follows, and the URL is accessible by /site/aaa or /site/bbb.

site
  └-- aaaa directory
  └-- bbbb directory

What do you want to do

  • siteI want the following to be the document root and the URL to be accessible as /aaaa and /bbb as well
  • I want
  • / to be able to access /aaa even if I access
  • /

if you write as follows:
    If
  • /aaaa/ or /, transition to /aaaa/ properly
  • However, /aaaa transitions to /site/aaaa/

That's why I'm in trouble.Could you please let me know who it is?

RewriteEngine on
RewriteBase/
RewriteCond%{REQUEST_URI}^/$[OR]
RewriteRule^$aaa/[R=301,L]
RewriteCond%{REQUEST_URI}!/site/
RewriteRule^(.*)$site/$1[L]

Also, conoha Wing was used and the document route could not be specified in httpd.conf.
I would appreciate it if you could give me your advice if there is any other way like the above.
I'm sorry to ask this question from a beginner, but I appreciate your cooperation.

.htaccess

2022-09-30 19:13

1 Answers

After converting (/aaaa→/site/aaaa) in the last RewriteRule, you will be redirected to add a tracking slash.
Before that, I think it would be good to insert a rule (/aaaa→/aaaa/) to attach a tracking slash.

RewriteRule^$aaa/[R=301,L]
RewriteRule^(aaaa|bbbb)$1/[R=301,L]
RewriteCond%{REQUEST_URI}!/site/
RewriteRule^(.*)$site/$1[L]


2022-09-30 19:13

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.