Jump to content

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


jpress07

Recommended Posts

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.

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.

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

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>

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)

 

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>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.