Solved

mod_rewrite with query string

Posted on 2013-01-17
4
371 Views
Last Modified: 2013-01-18
I currently have a site that uses URLs like the following:
www.mysite.com/index.php?Page=page1
www.mysite.com/?Page=page1

I would like to be able to use URLs like the following:
www.mysite.com/page1

I am using GoDaddy and have full access to my .htaccess file.  I have RewriteEngine On however, I do not know where to go next with this.

Thank you
0
Comment
Question by:LouSch7
  • 2
  • 2
4 Comments
 
LVL 26

Accepted Solution

by:
arober11 earned 500 total points
ID: 38788529
The following may be a good start:

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$  /index.php?Page=$1 [L]

Open in new window


If you need an explanation of the rule the the following article  is a good place to start.
0
 
LVL 3

Author Comment

by:LouSch7
ID: 38788639
I have added that to my .htaccess file however, I am now receiving an error message that says it was unable to load missing.html.php.  I use the below code in my header file in order to determine what file to include in the body of the site.

<?php
	If ($_GET['Page'] == ''){
		$myPageTitle = 'home';
	} else {
		$myPageTitle = $_GET['Page'];
	}
	$Page = $myPageTitle . ".php";
?>

Open in new window


And here is where the variable is used

<?php include $Page; ?>

Open in new window


Any thoughts?
0
 
LVL 26

Expert Comment

by:arober11
ID: 38792291
Not unless you provide the URL your trying to access and whether that file physically exists on the server, and in the specified location.
0
 
LVL 3

Author Comment

by:LouSch7
ID: 38792296
The solution was to get the URL instead of the page from the server variables. All seems to be working now, thank you!
0

Featured Post

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question