Solved

mod_rewrite with query string

Posted on 2013-01-17
4
373 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

713 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