Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

rewrite url using mod rewrite without redirection

this url is being rewritten

http://domain.com/embed/slideshow-image-list.js

to this

http://domain.com/code/embed/slideshow-image-list

current htaccess code

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [R=301,L]
RewriteRule ^embed/([^\.]+)\.js$ http://domain.com/code/embed/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /index.php/$1 [L]

its currently rewritten correctly, but if you visit the .js url it redirects to the full url.

im looking just to map it without redirection

like image 807
chris mccoy Avatar asked Jan 20 '13 00:01

chris mccoy


1 Answers

Don't supply the domain in the rule, just the path. With the full domain it will be redirected.

RewriteRule ^embed/([^\.]+)\.js$ /code/embed/$1 [L]

Alternately, if the resulting path is not a real file and should be handled by index.php, stip off the [L] so that the next rule will be executed:

RewriteRule ^embed/([^\.]+)\.js$ /code/embed/$1

Note that the mod_rewrite guide says the following, which would seem to indicate that the full URL path is okay, but I believe it compares against ServerName, not necessarily ServerAlias (I'm not 100% sure about that, but I've always used paths rather than full URLs in doing non-redirect rewrites):

Absolute URL

If an absolute URL is specified, mod_rewrite checks to see whether the hostname matches the current host. If it does, the scheme and hostname are stripped out and the resulting path is treated as a URL-path. Otherwise, an external redirect is performed for the given URL. To force an external redirect back to the current host, see the [R] flag below.

like image 185
David Ravetti Avatar answered Sep 18 '22 05:09

David Ravetti