?
Solved

mod_rewrite with query string

Posted on 2013-01-17
4
Medium Priority
?
385 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 2000 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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
This holiday season, we’re giving away the gift of knowledge—tech knowledge, that is. Keep reading to see what hacks, tips, and trends we have wrapped and waiting for you under the tree.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses
Course of the Month15 days, 23 hours left to enroll

850 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