Mobile app version of vmapp.org
Login or Join
Margaret670

: Htaccess problem with redirects dropping slash I'm trying to redirect individual URLs on http://olddomain.tld (retired WordPress site) to individual URLs on https://newdomain.tld (new WordPress site)

@Margaret670

Posted in: #Apache #Htaccess #Redirects #Wordpress

I'm trying to redirect individual URLs on olddomain.tld (retired WordPress site) to individual URLs on newdomain.tld (new WordPress site) using .htaccess.

Redirecting the home page works fine with Redirect 301 / newdomain.tld (so I know I didn't forget to turn on Rewrite engine, or anything like that).

None of the other redirects works correctly, however. Example: I write Redirect 301 /page/ newdomain.tld/page/in .htaccess, and then olddomain.tld/page/ redirects to newdomain.tldpage. That is, the redirect is present, but it drops the trailing slash in every case.

What could be causing this?

I tried all kinds of increasingly exotic variations of the olddomain.tld .htaccess, before finally getting the idea to see if trailing slashes are somehow getting dropped by newdomain.tld's .htaccess. Could something in here be doing it?

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


ps. It's not this, this, this, this, this or this.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Margaret670

2 Comments

Sorted by latest first Latest Oldest Best

 

@Kaufman445

There is nothing wrong in the WordPress provided .htaccess code, as it only does internal rewrites. No external redirect is being done in the newdomain.tld's .htaccess code as you've provided:

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


The ending slash is either being dropped by WordPress core, depending on the rewrite rules you (or your plugins) have set in WordPress or by some other server configuration.

To check if it is WordPress that is doing it, go to:


WordPress Admin Panel => Settings => Permalinks


and check the Permalink Settings. Then in Common Settings, check the ending of the URL structure. Most likely you don't have the ending slash (/) there.

So, if you are using Custom Structure like this:


newdomain.tld/%postname%

Make it as:


newdomain.tld/%postname%/

That should fix your problem. If it doesn't, it means the trailing slash is coming from somewhere else. If you have multiple plugins, try by disabling them & then enable one by one to check who is causing it.


Note: while testing URL redirects, always make sure you clear browser cache.


If none of it works, then your problem is coming from some other server configuration.

10% popularity Vote Up Vote Down


 

@Alves908

If the trailing slash is being "dropped" then there maybe something in the WordPress config at the destination site that is doing this. Check the network/HTTP traffic... at what point do you see the second redirect? What HTTP status is the second redirect?

If you type the new URL directly is the trailing slash still dropped?

However...


I write Redirect 301 /page/ newdomain.tld/page/ in .htaccess ...


The Redirect directive is a mod_alias directive. This has nothing to do with RewriteEngine, which is part of mod_rewrite. Different Apache modules work independently and you should avoid mixing redirects from both modules - you can get unexpected conflicts (since mod_rewrite runs first, regardless of the apparent order of these directives in .htaccess).

Since WordPress already uses mod_rewrite, you should change these redirects to use mod_rewrite instead and these should go before the existing WordPress directives. So, for example:

# Home page (ie. "/")
RewriteRule ^$ newdomain.tld/ [R=301,L]

# Other page (ie. "/page/")
RewriteRule ^page/$ newdomain.tld/page/ [R=301,L]


Note that there is no slash prefix on the RewriteRule pattern (as there is with mod_alias Redirect).


Could something in here be doing it?


That is simply the WordPress front controller - no that can't drop the trailing slash. But presumably there is some URL canonicalisation in the WordPress config itself?

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme