1

I've gone through and check other questions that have answers and can't seem to find what I'm looking for anywhere. Here are the options that I've tried so far...

This answer, this one and this one.

My problem right now is that when I go to example.com/account/, it goes to a 404 not found page. However when I go to example.com/account/1/ it loads the page as expected. Below is my current htaccess as it stands. I've tried all sorts of variations and nothing seems to work.

# .htaccess file

RewriteEngine on
Options -MultiViews +FollowSymLinks

# Rerwite the domain

RewriteCond %{HTTP_HOST} !^example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

# Rewrite conditions for each page type

RewriteCond /%{REQUEST_FILENAME} !-d
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9-]+)/$ /index.php?page=$1 [L]

RewriteCond /%{REQUEST_FILENAME} !-d
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/$ /index.php?page=$1&id=$2 [L]

# Disallow access to both this file and the config file

<Files .htaccess>
order allow,deny
deny from all
</Files>

<Files config.php>
order allow,deny
deny from all
</Files>

# Various error pages
ErrorDocument 300 /error/
ErrorDocument 400 /error/
ErrorDocument 403 /error/
ErrorDocument 404 /error/
ErrorDocument 408 /error/
ErrorDocument 500 /error/
ErrorDocument 503 /error/

Just as a note, I've edited the main domain rewrites to example.com as this site is in development and can't be public. So ignore that bit.

Community
  • 1
  • 1

2 Answers2

1

Have your rules like this:

RewriteEngine on
Options -MultiViews +FollowSymLinks
# Rerwite the domain

RewriteCond %{HTTP_HOST} !^example.com [NC]
RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]

# Rewrite conditions for each page type

# skip all files and directories from rules below
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ - [L]

RewriteRule ^([a-zA-Z0-9-]+)/?$ /index.php?page=$1 [L,QSA]

RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ /index.php?page=$1&id=$2 [L,QSA]
anubhava
  • 761,203
  • 64
  • 569
  • 643
1

I wouldn't put slashes in front of the variable. This works just fine for me.

Options -MultiViews 

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/?$ /index.php?page=$1&id=$2 [L]

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([a-zA-Z0-9-]+)/?$ /index.php?page=$1 [L]
Panama Jack
  • 24,158
  • 10
  • 63
  • 95
  • Thanks for the help Panama Jack and anubhava, I follow Panama Jack's advice and putting the longer URL first and adding the question marks seemed to fix it perfectly. :) – user4975578 Jun 04 '15 at 21:53
  • @user4975578 great if this helped you be sure and click the checkmark to the left. – Panama Jack Jun 04 '15 at 22:01