htaccess - URL 使用第二个参数时重写工作

htaccess - URL Rewrite working when second parameter used

我已经检查并检查了其他有答案的问题,但似乎无法在任何地方找到我要找的东西。以下是我到目前为止尝试过的选项...

这个answer, this one and this one.

我现在的问题是,当我转到 example.com/account/ 时,它会转到 404 未找到页面。但是,当我转到 example.com/account/1/ 时,它会按预期加载页面。下面是我当前的 htaccess。我已经尝试了各种变体,但似乎没有任何效果。

# .htaccess file

RewriteEngine on
Options -MultiViews +FollowSymLinks

# Rerwite the domain

RewriteCond %{HTTP_HOST} !^example.com [NC]
RewriteRule ^(.*)$ http://example.com/ [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= [L]

RewriteCond /%{REQUEST_FILENAME} !-d
RewriteCond /%{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9-]+)/([a-zA-Z0-9-]+)/$ /index.php?page=&id= [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/

请注意,我已将主域重写为 example.com,因为该站点正在开发中,不能 public。所以请忽略那一点。

你的规则是这样的:

RewriteEngine on
Options -MultiViews +FollowSymLinks
# Rerwite the domain

RewriteCond %{HTTP_HOST} !^example.com [NC]
RewriteRule ^(.*)$ http://example.com/ [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= [L,QSA]

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

我不会在变量前加斜杠。这对我来说很好用。

Options -MultiViews 

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

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