Mitya
Mitya

Reputation: 34556

htaccess redirect going to bizarre place

Quantum physics is trivial compared to htaccess. I'm trying to visibly redirect from one URL to another, i.e. complete with HTTP request. I have:

#RewriteCond %{REQUEST_URI} !(inc|out\.|admin|static|channel) [NC]
#RewriteRule ^([a-z\-]+)(/([a-z_]+))?/?$ channel/$1/$3 [L,R=301]

But unfathomably, that visibly bounces the user to

mydomain.com/home/xxxx/public_html... //etc

If I remove [L,R=301] it does do the redirect, but only silently. What's up?

Upvotes: 1

Views: 16

Answers (1)

anubhava
anubhava

Reputation: 785196

Quantum physics is trivial compared to htaccess

lol :)))

Use this rule with absolute target URL:

RewriteCond %{REQUEST_URI} !(inc|out\.|admin|static|channel) [NC]
RewriteRule ^([a-z-]+)(/([a-z_]+))?/?$ /channel/$1/$3 [L,NC,R=301]

Chnage is to add a / before channel in target URL. Without a RewriteBase directive in place and missing leading / in target URL it adds current directory before target URL while doing a full redirect.

PS: However I consider this a mod_rewrite bug. IMO it should consider current relative path from DocumentRoot as default RewriteBase.

Upvotes: 1

Related Questions