Jump to content

Help with simple rewrite


Andy-H

Recommended Posts

Can anyone help me with this, I am writing a website locally (WAMP) for my Dads decorating company and wish to rewrite the URLs to eliminate query strings,

 

I have a folder in www called DadSite and am working off the .htaccess file in that folder (I have already loaded the rewrite module in apache and restarted all services)

 

I wish to rewrite http://localhost/DadSite/index.php?page=(.*)

 

to http://localhost/DadSite/$1

 

I.e

A request to

http://localhost/DadSite/Home

 

will point to

 

http://localhost/DadSite/index.php?page=Home

 

But havent really used mod reqrite and wish for it to work when I transfer the site to a live server (probably shared host) in which the domain and public directory will be different.

 

I have tried many variants but still cant get it to work.

 

Options +FollowSymLinks

RewriteEngine On
RewriteRule index.php?page=(.*)$ $1  [NC,L]

 

Thats my latest attempt, which resulted in failure lol

 

Any help appreciated!

Link to comment
https://forums.phpfreaks.com/topic/191562-help-with-simple-rewrite/
Share on other sites

Fixed it, just put a .htaccess file in the www directory with this.

 

Options +FollowSymLinks

RewriteEngine On
RewriteRule ^(.*)$ DadSite/index.php?page=$1 [NC,L]

 

Now

 

http://localhost/Home

 

maps to

 

http://localhost/DadSite/index.php?page=Home

I don't follow you.  The goal of "search engine friendly" url rewriting is to take a parameterized real url like:

 

http://mysite.com/index.php?page=home and allow someone to instead use http://mysite.com/home/.

 

In that case the rewrite rule will parse the last part of the url and turn that into the parameter to page=.

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.