I have a pretty simple question about RewriteRule. I am using the isset($_GET) function to call pages into my index.html so when you click on a page the address in the address bar appears like this:

http://site.com/?p=contact

I would like to get rid of the ?p= in front of the contact so it appears like this:

http://site.com/contact

I have tried many different things, but this is the current state of my htaccess file:

Options +FollowSymLinks

AddType x-mapp-php5 .php

RewriteEngine On 

RewriteCond %{http_host} ^www\.codershane\.com [NC]
RewriteRule ^(.*)$ http://codershane.com/$1 [R=301,NC]

RewriteRule ^/contact /index.php?p=contact [R=301,L]

Additional info: the index.php does not show up in the address bar unless you type it, but I was under the impression that that is how it should be. You can access the pages using inxex.php or not using it. Also all the pages are located in a folder called pages.
Any help is appreciated, thanks guys.

Recommended Answers

All 12 Replies

Do not specify R=301 because it indicates a permanent redirect. You can remove line 10 I guess if you change line 8 to:

RewriteRule ^(.*)$ http://codershane.com/?p=$1 [NC]

Line 7 and 8 are only to remove the www and are working just fine.

When I change line 10 to the what you suggested, I get the error: "The page isn't redirecting properly".

Any suggestions?

No, not sure yet. I'd have to try on one of my domains. I'll get back to you.

No, not sure yet. I'd have to try on one of my domains. I'll get back to you.

Alright well, thanks for your help. I figured this would be a pretty simple request. I have tried a million different things and searched Google hundreds of times to no avail.

If anyone has any idea about this, please share with me, your help is greatly appreciated!

Member Avatar for diafol

From first post I assume this will work:

RewriteEngine On
RewriteRule ^([^/]*)$ /?p=$1 [L]

ardav, thank you for your help; however, this does not work.

That gives a 500 Internal Server Error. =(

Member Avatar for diafol

Does your htaccess file work at all? If not, upload the file as htaccess.txt then rename on the server via FTP to .htaccess. Otherwise, dunno, sorry.

Does your htaccess file work at all?

Yes, if you read the thread you would know that!

If not, upload the file as htaccess.txt then rename on the server via FTP to .htaccess. Otherwise, dunno, sorry.

If htaccess was disabled in the httpd.conf that would not help.

This is not my first time using a server, I just never done RrewriteRule. But thanks for the input.

PS: 5,409 posts and you reply to a topic with out reading it? Sigh...

commented: 7 posts and you feel the need to be a jerk to someone who was merely trying to help you? -3
Member Avatar for diafol

PS: 5,409 posts and you reply to a topic with out reading it? Sigh...

Dear email..., my most abject apologies for not picking up on the fact that you are a server guru and for skimming over a few things. Getting personal jibes from a newbie poster after I took the time to lend a hand? That's just not cool. I'm not going to get into a flame war, so I've put you on my ignore list. Do the same if you like, that way I won't annoy you with my half-arsed replies.

commented: User did not read the topic, and suggest things that made absolutely no sense, then wrote a very rude reply! -1

@ardav You ever heard of topic hijacking? Please stick to the topic. No need to get offended just because you get called out for not reading a topic.

Still need help with this if anyone has any .htaccess knowledge. Thanks again guys...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.