davestewart Posted February 9, 2010 Share Posted February 9, 2010 Hi there, I admit, I'm no expert on mod htaccess, in fact I normally use snippets gathered together to make my own Frankenstein's monster of an htaccess. So my question, which I suspect may be based on false assumptions is this: I would like to rewrite "tunes" to "files/music", which I am doing as follows: RewriteEngine On RewriteBase / RewriteRule ^tunes/?$ files/music [PT,L] I was under the impression that this happened internally to the server, and the user would see "tunes" in the URL bar, but Apache would serve the default file in "files/music". However, it looks as if the request is being completely redirected and the page served is "files/music". Is it possible to do what I think it should be doing, or am I just misinformed? Thanks, Dave Quote Link to comment https://forums.phpfreaks.com/topic/191470-rewritten-url-is-showing-the-new-url-in-the-browser/ Share on other sites More sharing options...
RussellReal Posted February 9, 2010 Share Posted February 9, 2010 You're not misinformed.. it does do what you think it does, however, I don't exactly see what is wrong with that code.. try this: RewriteEngine On RewriteRule ^tunes.*$ files/music/ [L] Quote Link to comment https://forums.phpfreaks.com/topic/191470-rewritten-url-is-showing-the-new-url-in-the-browser/#findComment-1009346 Share on other sites More sharing options...
davestewart Posted February 9, 2010 Author Share Posted February 9, 2010 That works great for the URL, but now the links in the page are missing the leading "tunes/" - they just appear to be in the web root. What are we missing? Quote Link to comment https://forums.phpfreaks.com/topic/191470-rewritten-url-is-showing-the-new-url-in-the-browser/#findComment-1009357 Share on other sites More sharing options...
RussellReal Posted February 9, 2010 Share Posted February 9, 2010 lol, set the images and stuff on the page to search from the main directory on.. for example instead of: main.jpg ^^ that will point the file to http://whatever.com/path/to/phpfile/main.jpg use /main.jpg ^^ that will point the file to http://whatever.com/main.jpg understand? Quote Link to comment https://forums.phpfreaks.com/topic/191470-rewritten-url-is-showing-the-new-url-in-the-browser/#findComment-1009744 Share on other sites More sharing options...
davestewart Posted February 9, 2010 Author Share Posted February 9, 2010 Ah no - that's the PROBLEM! The rewritten URL "tunes" is not being reflected in the links in the page, which are all relative. .htaccess rewrite: Realpath: /files/music/ RewritePath: /tunes/ Page URL: www.domain.com/tunes/ Page links: Link href: ./some-tune.mp3 Supposed file path: www.domain.com/tunes/some-tune.mp3 Actual file path: www.domain.com/some-tune.mp3 So for some reason the "tunes" part of the rewrite is not being reflected in the page links, even though they are relative and the page is showing "tunes" quite happily. Any ideas? Thanks, Dave Quote Link to comment https://forums.phpfreaks.com/topic/191470-rewritten-url-is-showing-the-new-url-in-the-browser/#findComment-1009757 Share on other sites More sharing options...
RussellReal Posted February 10, 2010 Share Posted February 10, 2010 RewriteEngine On RewriteRule ^tunes(?:/(.*))?$ files/music/$1 [L] Quote Link to comment https://forums.phpfreaks.com/topic/191470-rewritten-url-is-showing-the-new-url-in-the-browser/#findComment-1009789 Share on other sites More sharing options...
davestewart Posted February 10, 2010 Author Share Posted February 10, 2010 Nope. It's not a regexp thing I don't think. Either my server is off, or there's something else up with the htaccess. I'm going to sleep on this one. Thanks for you efforts in the meantime though. Quote Link to comment https://forums.phpfreaks.com/topic/191470-rewritten-url-is-showing-the-new-url-in-the-browser/#findComment-1009791 Share on other sites More sharing options...
RussellReal Posted February 10, 2010 Share Posted February 10, 2010 yes.. it is.. my old regex just matched tunesANYTHING_ELSE but didn't tell apache where to fetch any other files.. and so it all is just a redirect to the index page.. Quote Link to comment https://forums.phpfreaks.com/topic/191470-rewritten-url-is-showing-the-new-url-in-the-browser/#findComment-1009813 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.