Go Back   HostGator Peer Support Forums > HostGator Peer Support Forums > Shared Hosting Support

Notices

Reply
 
Thread Tools
  #1  
Old 03-08-2006, 04:46 AM
polarisdigital polarisdigital is offline
Hatchling Croc
 
Join Date: Mar 2006
Posts: 4
Angry .htaccess issue

I have searched through the forum and can't find an answer to this problem. So I am hoping someone on here can help me.

I have a site that navigates of requests to
Code:
http://mydomain.com/index.php?section=<sectionname>&page=<pagename>
I am trying to create a .htaccess file so that the url above looks like the one below to everyone else:

Code:
http://mydomain.com/<sectionname>/<pagename>
but I am having a little trouble. With rewrite on I would have assumed that a line like the one below would have worked, but I'm not having much luck.


Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+)/(.+) /index.php?section=$1&page=$2 [L]
Can anyone help please? I'm pully my hair out here. Thank you
Reply With Quote
  #2  
Old 03-08-2006, 07:51 AM
Serra's Avatar
Serra Serra is offline
Veteran Croc
 
Join Date: Feb 2005
Location: Orange Park, FL
Posts: 5,073
Default Re: .htaccess issue

Quote:
Originally Posted by polarisdigital
I have searched through the forum and can't find an answer to this problem. So I am hoping someone on here can help me.

I have a site that navigates of requests to
Code:
http://mydomain.com/index.php?section=<sectionname>&page=<pagename>
I am trying to create a .htaccess file so that the url above looks like the one below to everyone else:

Code:
http://mydomain.com/<sectionname>/<pagename>
but I am having a little trouble. With rewrite on I would have assumed that a line like the one below would have worked, but I'm not having much luck.


Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+)/(.+) /index.php?section=$1&page=$2 [L]
Can anyone help please? I'm pully my hair out here. Thank you

So what is the problem? When you go to
Code:
http://mydomain.com/<sectionname>/<pagename>
you don't get

Code:
http://mydomain.com/index.php?section=<sectionname>&page=<pagename>
because it doesn't work the other way around... you can't go to the second one and get shown the first.
__________________
Six stages of Dedi Ownership

Fashionable broken link
image included
Reply With Quote
  #3  
Old 03-08-2006, 08:00 AM
polarisdigital polarisdigital is offline
Hatchling Croc
 
Join Date: Mar 2006
Posts: 4
Default Re: .htaccess issue

It seems to be picking up the first request for section, but not the request for page.

I am running a PHP diagnostic script to test it, which outputs the $_GET['section'] and $_GET['page'] values. It seems to have no problem picking up the section request, but not the page request.
Reply With Quote
  #4  
Old 03-08-2006, 08:08 AM
polarisdigital polarisdigital is offline
Hatchling Croc
 
Join Date: Mar 2006
Posts: 4
Default Re: .htaccess issue

OK, my mistake. It is working as it should as long as both /<section>/<page> are included.

If I just give /<section> the page fails. I have built a defaulting page into the script if the section is given, but if I leave out the <page> section I get a standard 404 error (Not Found).

If I enter /<section// then it does work. Is there a way of making the .htaccess work as desired even if the <page> attribute is not included in the URL?
Reply With Quote
  #5  
Old 03-08-2006, 02:24 PM
Serra's Avatar
Serra Serra is offline
Veteran Croc
 
Join Date: Feb 2005
Location: Orange Park, FL
Posts: 5,073
Default Re: .htaccess issue

Quote:
Originally Posted by polarisdigital
OK, my mistake. It is working as it should as long as both /<section>/<page> are included.

If I just give /<section> the page fails. I have built a defaulting page into the script if the section is given, but if I leave out the <page> section I get a standard 404 error (Not Found).

If I enter /<section// then it does work. Is there a way of making the .htaccess work as desired even if the <page> attribute is not included in the URL?
Just add another line without the page on it. It will use that one instead.
__________________
Six stages of Dedi Ownership

Fashionable broken link
image included
Reply With Quote
  #6  
Old 03-08-2006, 02:33 PM
polarisdigital polarisdigital is offline
Hatchling Croc
 
Join Date: Mar 2006
Posts: 4
Default Re: .htaccess issue

Quote:
Originally Posted by Serra
Just add another line without the page on it. It will use that one instead.
Thank you for you help. I tried you suggestion and got an Apache internal error. When I reverted, things were working again, so I think that was an invalid statement.

Could you post an example of what you were suggesting, if its not too much trouble.

Kind regards
Reply With Quote
  #7  
Old 03-09-2006, 01:40 PM
microscripts.net microscripts.net is offline
Hatchling Croc
 
Join Date: Sep 2005
Posts: 4
Default Re: .htaccess issue

Use this rewrite rule:

Code:
RewriteRule ^(.*)/(.*)$ /index.php?section=$1&page=$2 [L]
Reply With Quote
  #8  
Old 03-09-2006, 07:31 PM
Serra's Avatar
Serra Serra is offline
Veteran Croc
 
Join Date: Feb 2005
Location: Orange Park, FL
Posts: 5,073
Default Re: .htaccess issue

Ok, that works, but why it solve the problem? I guess I don't understand how all of that relates to the /. I see that the (.*) means those are now optional, but doesn't the / still cause a problem?

Why wouldn't adding this work?

RewriteRule (.+) /index.php?section=$1 [L]
__________________
Six stages of Dedi Ownership

Fashionable broken link
image included
Reply With Quote
  #9  
Old 03-09-2006, 07:40 PM
microscripts.net microscripts.net is offline
Hatchling Croc
 
Join Date: Sep 2005
Posts: 4
Default Re: .htaccess issue

Because then you could get something like /index.php?section=timmy/index.php?someothershit

or

/index.php?section=http://www.comcast.net

etc.

to limit it even more you could add .html to the call

Code:
RewriteRule ^(.*)/(.*).html$ /index.php?section=$1&page=$2 [L]
and call it as http://mydomain.com/<sectionname>/<pagename>.html
Reply With Quote
  #10  
Old 03-10-2006, 09:19 AM
Serra's Avatar
Serra Serra is offline
Veteran Croc
 
Join Date: Feb 2005
Location: Orange Park, FL
Posts: 5,073
Default Re: .htaccess issue

Ok, would that work for both?

http://domain.com.index.php?section=1&page=2
and
http://domain.com.index.php?section=1

Where one would be

/section/page/

and the other would be

/section/
__________________
Six stages of Dedi Ownership

Fashionable broken link
image included
Reply With Quote
  #11  
Old 03-21-2008, 08:10 AM
Birmingham's Avatar
Birmingham Birmingham is offline
Hatchling Croc
 
Join Date: Jun 2007
Location: Birmingham, WM, England, GB, UK
Posts: 39
Arrow Re: .htaccess issue

cheers guys ive been strggling wth this.... htaccess url rewrites is new to me and my script jst wasnt working bt that little line by microscripts.net got me on my way. thanks!
Reply With Quote
Reply

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT -5. The time now is 06:45 AM.