Solved

mod_rewrite with query string

Posted on 2013-01-17
4
370 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
If you've heard about htaccess and it sounds like it does what you want, but you're not sure how it works... well, you're in the right place. Read on. Some Basics #1. It's a file and its filename is .htaccess (yes, with a dot in the front). #…
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 …

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now