13

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

0

1 Answer 1

21

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.

Sign up to request clarification or add additional context in comments.

5 Comments

Oh, you'll probably need to remove the [L] if the /code/embed/slideshow-image-list isn't an actual file and is supposed to be handled by index.php via the following rules.
I updated the answer to reflect the previous comment and to add a note from the Apache documentation.
combination of things yours fixed it, but it was also a codeigniter issue, had to change a variable for the uri_protocol, thanks.
"Otherwise, an external redirect is performed for the given URL" - missed that important info in the docs :-/
what if I want to use the old path and just change the url ? for example I have a file called /test.php and when it's accessed I want the url to be /test but it should load the same file (/test.php)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.