Score:-1

How to fix domain redirect with slash using Apache2 and Bitnami?

in flag

I'm running a Wordpress website with Bitnami which confused me a lot of ways.

The issue is when you click a link www.domain.com/ja/ then it goes to www.domain.comja because there is a missing slash /

EDIT: I discovered how it handles www.domain.com/ja without "/" in the last works fine as I expected, otherwise www.domain.com/ja/ with "/" slash it ended up with www.domain.comja

I've tried a lot of ways to solve this issue and still no solution.

Here is my apache2 conf from /opt/bitnami/apps/wordpress/conf/httpd-app.conf

RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1/ [R=permanent,L]
RewriteRule ^index\.php$ - [S=1]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
kz flag
Nothing in the Apache config you've posted would cause this. What do you see in the network traffic? Some kind of 3xx redirect I assume? What is the status? And to confirm, _both_ slashes are "removed"? What is the HTML of the link in question?
in flag
I followed to confirm the slash is removed... so I discovered the cause, edited my question
kz flag
"I discovered the cause" - So, what is the "cause"? You've described the _effect_ in the question, not the "cause"? (If you know the "cause" then you are close to a solution.) Please address _all_ the points asked in my comment above. However, the first rule in your config _removes_ the www subdomain, but all your examples (including the resulting URL) include the www subdomain? Please confirm.
in flag
Sorry, and yes, the effect since you suggested me to confirm the slash. It removes the www subdomain which is fine because it is not part of the issue.
kz flag
"It removes the www subdomain which is fine because it is not part of the issue." - or is it? That is the only redirect you have in the config you posted. So, is there an _additional_ redirect that removes the slashes? What exactly do you see in the network traffic?
in flag
Well, the truth is that I don't have any knowledge about network traffic, the reason why I ask a question here because I am not an expert in networking
kz flag
Open the browser developer tools (eg. in Google Chrome), go to the "Network" tab (check "Disable cache"), make a request to `domain.com/ja/` and record the results... these are the HTTP requests and responses the browser is making. This should give you a clue as to what is actually happening... how many redirects are being triggered, what type and what is triggering them (check the HTTP response headers on the redirect response). This is the first step to debugging an issue like this.
Score:1
bm flag

I am only can think 3 possible reasons:

  1. Your browser cached 301 redirect from an old rewrite rule or something similar. Try to access the URL from other browser to confirm it.

  2. The redirector is from the Wordpress/or the plugin. Try to disable all plugin first or change index.php to empty file.

  3. You still have the wrong rule like:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} /(.+)/$
    RewriteRule ^ https://www.example.com%1 [L,R=301]
    

above will redirect like your case, so change to:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} (.+)/$
RewriteRule ^ %1 [L,R=301]
in flag
The issue is when you click "www.domain.com/ja/" then it redirects to the page with your browser ended up with "www.domain.comja"
bm flag
@Ivan Sorry for missunderstood, I updated the answer
in flag
Regarding to reason 1#: I enter https://www.example.com/ja it redirects me to https://www.example.com/opt/bitnami/apps/wordpress/htdocs/ja in other browser
in flag
Reason #2 the current wordpress site is not using redirector plugin and the index.php is required to load wordpress header. Reason #3 I copypasted your code and restarted the apache server, then the most directory like /ja/ were not found
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.