jpress07 Posted June 28, 2008 Share Posted June 28, 2008 hi guys, when a user types in sitename.com/home-insurance into their browser, how do I get it to redirect to sitename.com/home-insurance.php ? many thanks in advance! Cheers, JP Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted June 28, 2008 Share Posted June 28, 2008 Sounds like you're talking about Mod_Rewrite: Put this into a .htaccess file: (I'm assuming the server you're using is using Apache) Options +FollowSymLinks RewriteEngine on RewriteRule ^home-insurance$ /home-insurance.php [L] Hopefully it works. Quote Link to comment Share on other sites More sharing options...
br0ken Posted June 28, 2008 Share Posted June 28, 2008 Mod-rewrite would do the job but it can be confusing for someone has never used it. If it's just the one redirect you want I would do the following. Create a folder called 'home-insurance' and inside that create a file named 'index.php' with the following code inside: <?php header("http://sitename.com/home-insurance.php"); exit; ?> If you wanted several redirects this technique would still work but would take some time to create all of the different redirects. Quote Link to comment Share on other sites More sharing options...
jpress07 Posted June 28, 2008 Author Share Posted June 28, 2008 hi guys, thanks for your speedy replies. Ok I'm a real newbie, anyway I've got: RewriteEngine on RewriteCond %{HTTP_HOST} ^sitename.com$ RewriteRule (.*) http://www.sitename.com/$1 [R=Permanent] Options +FollowSymLinks RewriteEngine on RewriteRule ^home-insurance$ /home-insurance.php [L] but it's not happening for me! Can you please tell me where I've gone wrong? Thanks, JP Quote Link to comment Share on other sites More sharing options...
jpress07 Posted June 28, 2008 Author Share Posted June 28, 2008 hmm, sorry, the above seems to work but NOT if someone types sitename.com/Home-Insurance (sentence case) do you know how to fix that? Quote Link to comment Share on other sites More sharing options...
br0ken Posted June 28, 2008 Share Posted June 28, 2008 If you only want the one redirect you would find it much easier and less time consuming to use my method stated above. Quote Link to comment Share on other sites More sharing options...
jpress07 Posted June 28, 2008 Author Share Posted June 28, 2008 hi br0ken, I plan to have several redirects for this site Quote Link to comment Share on other sites More sharing options...
marotta1 Posted June 28, 2008 Share Posted June 28, 2008 You could just use the following for the pages you want in your .htaccess file. So if you want http://www.yourdomain.com/home-insurance to display in the address browser bar. It will actually output the home-insurance.php. Your looking for pretty URL's right? <Files ^(page1toredirect|page2toredirect|pagetoredirect)$> ForceType application/x-httpd-php </Files> or my server requires <Files ~ ^(page1toredirect|page2toredirect|pagetoredirect)$> ForceType x-mapp-php </Files> Quote Link to comment Share on other sites More sharing options...
cooldude832 Posted June 28, 2008 Share Posted June 28, 2008 If you only want the one redirect you would find it much easier and less time consuming to use my method stated above. modrewrites are the prefered way to go php header redirects are really designed for internal script actions that are so dynamic apahe's modrewirte can't aid it. my mod rewite for specific pages is Options +FollowSymLinks Options +Indexes RewriteEngine on RewriteBase / RewriteRule ^about/$ index.php?Page_Request=about/index [NC,L] RewriteRule ^about$ index.php?Page_Request=about/index [NC,L] RewriteRule ^archives/$ index.php?Page_Request=archives/index [NC,L] RewriteRule ^archives$ index.php?Page_Request=archives/index [NC,L] RewriteRule ^Events/$ index.php?Page_Request=events/index [NC,L] RewriteRule ^Events$ index.php?Page_Request=events/index [NC,L] RewriteRule ^gallery/$ index.php?Page_Request=gallery/index [NC,L] RewriteRule ^gallery$ index.php?Page_Request=gallery/index [NC,L] Works very simple save it into a file called .htaccess and put it in your root folder (usually www on a uniform server build) Quote Link to comment Share on other sites More sharing options...
Goldeneye Posted June 28, 2008 Share Posted June 28, 2008 You need to include the RewriteBase command before any of your Rewrite Conditions/Rules. EXAMPLE So if you store your scripts at http://example.com/scripts/, then you'll need to put this line after you turn on the Rewrite Engine: RewriteBase /scripts Otherwise, just use: RewriteBase / (if you store them at http://example.com/) Also You only need the RewriteEngine On command once, unless you use RewriteEngine Off before executing anymore rules/conditions. Options +FollowSymLinks RewriteEngine on #RewriteCond %{HTTP_HOST} ^sitename.com$ #RewriteRule (.*) http://www.sitename.com/$1 [R=Permanent] RewriteRule ^home-insurance$ /home-insurance.php [L] The Pounds (#) indicate a comment, just remove them if you want the rule/condition to execute. I assume you've tried testing it by inputing /home-insurance/ instead of /home-insurance.php ? You have to manually input this into the address bar, not click on a link because it won't do anything unless you change the link's <a href="home-insurance.php">Home Insurance</ a> to <a href="home-insurance/">Home Insurance</ a> Quote Link to comment 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.