2

我对重写规则有一些困难。我的.htaccess样子是这样的:

<IfModule mod_rewrite.c>
RewriteEngine On

RewriteRule admin/add-category$ adm_add_category.php [NC]
RewriteRule admin/categories-management$ adm_categories_management.php [NC]
RewriteRule admin/user-settings/(.*)$ adm_user_settings.php?update=$1 [NC]
RewriteRule admin/website-settings/(.*)$ adm_website_settings.php?update=$1 [NC]
RewriteRule admin/users-management$ adm_users_management.php [NC]
RewriteRule admin/websites-management$ adm_websites_management.php [NC]

RewriteRule settings/profile$ changesettings.php [NC]
RewriteRule settings/websites$ my_websites.php [NC]
RewriteRule settings/password$ changepassword.php [NC]
RewriteRule settings/logout$ logout.php [NC]

RewriteRule pages/index$ index.php [NC]
RewriteRule pages/access$ access.php [NC]
RewriteRule pages/submit-url$ submit_url.php [NC]
RewriteRule pages/online-users$ online_users.php [NC]
RewriteRule pages/register$ register.php [NC]
RewriteRule pages/websites$ websites_list.php [NC]
RewriteRule pages/websites/(.*)$ websites_list.php?page=$1 [NC]
RewriteRule pages/contact$ contact.php [NC]

RewriteRule search/(.*)$ search.php?term=$1 [NC]
RewriteRule category/(.*)$ category.php?name=$1 [NC]    

RewriteRule profile/(.*)$ profile.php?username=$1 [NC]
RewriteRule website/(.*)$ website.php?name=$1 [NC]


除以下内容外,所有重写均有效:

RewriteRule search/(.*)$ search.php?term=$1 [NC]
RewriteRule category/(.*)$ category.php?name=$1 [NC]    

RewriteRule profile/(.*)$ profile.php?username=$1 [NC]
RewriteRule website/(.*)$ website.php?name=$1 [NC]

尝试加载特定配置文件(例如 /profile/exampleguy)时,会显示 404 错误。有谁知道这会导致什么?

404 看起来像:

The requested URL /profile/exampleguy was not found on this server. 

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

如果您需要更多信息,请告诉我,我非常感谢您的帮助!

4

2 回答 2

5

在每个规则中添加L标志以使其生效[NC,L],然后添加:

Options +FollowSymLinks -MultiViews

在顶部.htaccess

于 2013-09-25T20:44:39.817 回答
1

您是否尝试过在某些重写条件下工作以重定向到默认页面?

RewriteCond %{REQUEST_FILENAME} !-d  //Rewrites if the directory doesn't exist
RewriteCond %{REQUEST_FILENAME} !-f  //Rewrites if the file doesn't exist

RewriteRule ^(.*)$ index.php?$1 [L,QSA]  // Change this to suit your needs

另外,我猜你得到的是 404,因为像 /profile/ 这样的目录实际上存在,但不是“exampleguy”,如果这些目录中没有另一个 .htaccess 来捕捉问题,那么服务器将尝试找到该页面(失败......)

于 2013-09-25T20:43:44.523 回答