Mobile app version of vmapp.org
Login or Join
YK1175434

: Which redirect directive with Apache chooose to use among duplicates? We are using Apache server with a .config file to do permanent 301 redirects. The web site is mostly maintained and content

@YK1175434

Posted in: #301Redirect #Redirects

We are using Apache server with a .config file to do permanent 301 redirects.

The web site is mostly maintained and content is provided by the client. This particular web site changes very often, and so I am frequently asked to add to the 301 redirects as the pages change.

This has resulted in multiple redirects for the same URLs as below:

Redirect 301 "/foo/old" "/foo/new"
Redirect 301 "/foo/old" "/foo/bar/new"
Redirect 301 "/foo/old" "/new/foo"


Which one of these redirects will apache use? Configtest tells me that the syntax is OK.

10.01% popularity Vote Up Vote Down


Login to follow query

More posts by @YK1175434

1 Comments

Sorted by latest first Latest Oldest Best

 

@Ann8826881

Which one of these redirects will apache use?

Apache will process the .Htaccess file from top to bottom. When a condition is met, it processes the condition. When done, Apache will start at the top and process all the rules again to ensure that there are no more matching conditions.

Using your example, once the first rule

Redirect 301 "/foo/old" "/foo/new"


is matched against the condition "/foo/old" it processes the rule and starts again. However, the request is now "/foo/new" and does not match any condition defined within the rules. Therefore only the first rule in your example can be processed. You should only have one rule per condition.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme