|
#1
|
|||
|
|||
|
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> Code:
http://mydomain.com/<sectionname>/<pagename> Code:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.+)/(.+) /index.php?section=$1&page=$2 [L]
|
|
#2
|
||||
|
||||
|
Quote:
So what is the problem? When you go to Code:
http://mydomain.com/<sectionname>/<pagename> Code:
http://mydomain.com/index.php?section=<sectionname>&page=<pagename> |
|
#3
|
|||
|
|||
|
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. |
|
#4
|
|||
|
|||
|
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? |
|
#5
|
||||
|
||||
|
Quote:
|
|
#6
|
|||
|
|||
|
Quote:
Could you post an example of what you were suggesting, if its not too much trouble. Kind regards |
|
#7
|
|||
|
|||
|
Use this rewrite rule:
Code:
RewriteRule ^(.*)/(.*)$ /index.php?section=$1&page=$2 [L] |
|
#8
|
||||
|
||||
|
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] |
|
#9
|
|||
|
|||
|
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] |
|
#10
|
||||
|
||||
|
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/ |
|
#11
|
||||
|
||||
|
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!
__________________
Birmingham Web Development Partnership |
![]() |
| Bookmarks |
«
Previous Thread
|
Next Thread
»
| Thread Tools | |
|
|
All times are GMT -5. The time now is 06:45 AM.









