Mobile app version of vmapp.org
Login or Join
Kristi941

: Execution order of different htaccess redirects It seems that no matter what I search I just can't understand why I keep getting this issue and I for some reason can't find a good explanation

@Kristi941

Posted in: #301Redirect #Htaccess #Redirects

It seems that no matter what I search I just can't understand why I keep getting this issue and I for some reason can't find a good explanation on how it works.
Also sorry if this quest was asked before but I have been searching for an answer for 2 days and just can't find the answer.
(probably searching the wrong keywords)

BUT.

I am currently having an issue regarding my redirects that use the Redirect and RewriteRule functions.

The context is as follows.

The company I work for has recently migrated and updated its website from server and design.
This of course means there are pages that are not available anymore or URLs that need to be redirected.

The issue first came up when I was walking through all the redirects and noticed that some redirects didn't go to the page they should.

Below is a piece of the the .htaccess file that is giving me the issues.
The lines are in the same order as they are in my .htaccess.

<IfModule mod_rewrite.c>
RewriteEngine On

Redirect 301 /nieuws/168/Luchtvaartmaatschappij-delft-onderspit-bij-Hoge-Raad [https domainname]/nieuws
Redirect 301 /nieuws/145/Artikel-Telegraaf-Vertraging [https domainname]/nieuws
Redirect 301 /nieuws/145/Artikel-Telegraaf:-Vertraging.html [https domainname]/nieuws
Redirect 301 /nieuws/108/Wie-gaat-nu-via-(reis)verzekeraars-werken-`Reisagenten-kunnen-klanten-ook-verwijzen` [https domainname]/blog/euclaim-gaat-nu-via-reis-verzekeraars-werken
Redirect 301 /nieuws/136/Technisch-mankement-geen-overmacht.html [https domainname]/blog/technisch-mankement-geen-overmacht

RewriteRule ^nieuws/([1-9]|[1-9][0-9]|[1-9][0-9][0-9]||[1-9][0-9][0-9][0-9])/.*$ /nieuws [R=301,NC,L]


The problem is when I go to /nieuws/136/Technisch-mankement-geen-overmacht.html I get redirected to /nieuws.

The issue

Now the issue isn't that I don't know what part of the htaccess is causing this but more why and how can I solve this.

The RewriteRule is picking up the URL and redirecting to /nieuws and it doesn't matter where I place it as it just keeps picking it up without fail.
I tried putting the RewriteRule at the top, bottom, right behind the redirects like in my example but nothing seems to stop the RewriteRule from taking the top priority.

Is this normal behaviour or am I doing something wrong here?

If you need any more info please let me know.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @Kristi941

1 Comments

Sorted by latest first Latest Oldest Best

 

@Jamie184

Redirect belongs to mod_alias, whereas RewriteRule is a mod_rewrite directive. Two different modules. Different modules execute independently and at different times during the request.

Unless you have a customised Apache server then mod_rewrite always executes before mod_alias, despite the apparent order of the directives in the Apache config file (eg. .htaccess).

Generally, if you are using mod_rewrite for redirecting (and/or URL-rewriting) then you should use mod_rewrite for all your redirects to avoid such conflicts.

Note that you will need to make sure any intermediary caches have been cleared before testing since 301s are cached hard by the browser.




Redirect 301 /nieuws/168/Luchtvaartmaatschappij-delft-onderspit-bij-Hoge-Raad [https domainname]/nieuws



As an example, since Redirect is prefix matching, the equivalent RewriteRule directive would be:

RewriteRule ^nieuws/168/Luchtvaartmaatschappij-delft-onderspit-bij-Hoge-Raad(.*) example.com/nieuws [R=301,L]


However, if this is intended to be an exact match then:

RewriteRule ^nieuws/168/Luchtvaartmaatschappij-delft-onderspit-bij-Hoge-Raad$ example.com/nieuws [R=301,L]

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme