Jump to content

make sitename.com/home-insurance go to sitename.com/home-insurance.php


jpress07

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

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)

 

Link to comment
Share on other sites

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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.