panoramic
panoramic

Reputation: 193

.htaccess Redirect / Rewrite with wildcards

Over the past year I have been using a WordPress theme that has forced me to incorporate a series of 301 redirects in order to allow users to view subsequent page through the page navigation. That is, the main page’s URL would be http://example.com, when the user presses the page navigation arrow http://example.com/page/2/ is attempted to be loaded, but in order to view the content the user must be redirected to http://example.com/main/page/2/

Redirect 301 http://example.com/page/*/ http://example.com/main/page/*/

The following code works once the user is on a page other than page one and uses the page navigation, but not if they start on main page. That is if the user is on http://example.com/main/page/2/ and use the page navigation they will be properly redirected to http://example.com/main/page/3/. However if they are on the main page and attempt to use the page navigation they will be sent to http://example.com/page/2/ Any ideas?

Upvotes: 1

Views: 117

Answers (1)

Ravi K Thapliyal
Ravi K Thapliyal

Reputation: 51711

Your Redirect directive should be

Redirect 301 /page http://example.com/main/page

Redirect does not support full pattern matching like RedirectMatch and so doesn't recognize * but it can still handle simple prefix-matching i.e. anything after /page automatically gets appened to your target URL. And, like in my example above, the old URL path starts with a /.

Upvotes: 1

Related Questions