Psycho Posted June 14, 2022 Share Posted June 14, 2022 I don't have any prior experience with mod_rewrite and am trying to create internal redirects to create a test harness for an application. I am using Apache on an XAMPP install. I have enabled mod_rewrite by modifying the conf file. I can get some rules to work that will modify the URL in the browser (i.e. external redirect), but I cannot get ones to work that do an internal redirect. For example, if I have two files: foo.html and bar.html If I use a Redirect in my .htaccess file RewriteEngine on Redirect "/foo.html" "/bar.html" Then attempting to load localhost:8080/foo.html is redirected in the browser address bar and in the loaded content. However, what I want to happen is to enter the URL for foo.html and only see the content for bar.html - i.e. the address in the browser should still display foo.html. Based on the examples, I've seen I need to use a RewriteRule. I have tried a couple different ways to do this (see below) based on info at apache.org. But when I do, I still get the content for foo.html. It's as if the RewriteRule is not doing anything. Here is the format I think I should be using so the url in the browser is not changed: RewriteEngine on RewriteRule "^/foo\.html$" "/bar.html" [PT] Here is another version using RewriteRule, that I think should work just like Redirect (which is working) RewriteEngine on RewriteRule "^/foo\.html$" "bar.html" [R] But, as stated above, neither of these work - I just get the content for foo.html (and the URL is unchanged). Any ideas? FWIW: Here is the actual logic I want to achieve using a RedirectMatch but, as stated above, I want to do with as an internal redirect which is hidden from the calling agent. RedirectMatch "/data/FAMStaticData/(.*).txt(.*)" "http://localhost:8080/index.php?file=$1" Quote Link to comment https://forums.phpfreaks.com/topic/314926-issue-with-mod_rewrite-and-internal-redirect/ Share on other sites More sharing options...
benanamen Posted June 14, 2022 Share Posted June 14, 2022 Here you go Line 1 enables the rewrite engine. Line 2 contains the RewriteRule directive: The pattern ^old.html$ matches the page which starts (^) and ends ($) with old.htm. The substitution is the new.htm page. The flag [NC] means the pattern is not case-sensitive. When a user tries to access the old page, the server shows the contents from the new.htm page instead. RewriteEngine On RewriteRule ^old.htm$ new.htm [NC] Quote Link to comment https://forums.phpfreaks.com/topic/314926-issue-with-mod_rewrite-and-internal-redirect/#findComment-1597288 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.