I'm trying to rewrite domain.com/index.php?section=whatever and domain.com/index.php?section=whatever&page=whatever and I'm running into a snafu. Here's my htaccess: Code: Order deny,allow RewriteEngine on RewriteRule ^section/(.+) /index.php?section=$1 [nc] RewriteRule ^section/(.*)/page/(.*) /index.php?section=$1&page=$2 [nc] Code (markup): The first rewrite works, but if there is a trailing slash, it gets put in the variable whenever I do a _GET. The second one doesn't seem to work at all. Also, I don't know that I want (.*). Maybe it'd be safer with just any numbers, letters, and underscores. Thoughts?
Options +FollowSymLinks +Indexes RewriteEngine on RewriteBase / RewriteRule ^section/([^.]+)/page/([^.]+)$ index.php?section=$1&page=$2 [L] RewriteRule ^section/([^.]+)$ index.php?section=$1 [L]
Try this. It is optimized for stupid Apaches <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteBase / # only non www version RewriteCond %{HTTP_HOST} !^domain.com$ [NC] RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^(.*)$ index.php?section=$1 RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule ^([A-Za-z_\-]+)/([A-Za-z_\-]+) index.php?section=$1&page=$2 </IfModule> Code (markup):
Thanks. That worked great. Now, if I wanted to remove section and page from the string so that it's domain.com/whatevera/whateverb, how would I do that?
Ok, so some of this works and some doesn't Here's what I have: <IfModule mod_rewrite.c> Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ index.php?section=$1 RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/]+)/([^/]+)/?$ index.php?section=$1&page=$2 </IfModule> Code (markup): The problem I have now is that the last rewrite isn't working right. I want domain.com/index.php?section=foo&page=bar to be domain.com/foo/bar. Right now, it's basically telling me that section=foo/bar and isn't giving the page var a value. That make sense?
I think you have the last line wrong. How about this? RewriteRule ^([A-Za-z0-9_\-]+)/([A-Za-z0-9_\-]+)$ index.php?section=$1&page=$2 Code (markup):