1

这是我的 htaccess 代码:

<IfModule mod_rewrite.c> 
Options +FollowSymLinks 
RewriteEngine on

RewriteCond %{THE_REQUEST} ^(GET|HEAD|POST)\ /Songs/Songs\.php\?movie=([^&\ ]+)([^\ ]*)
RewriteRule ^/Songs/%3?%4 [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^/?Songs/(.*)$ /Songs/Songs.php?movie=$1 [L,QSA]


</IfModule>

它的重定向非常像

localhost/Songs/Songs.php?movie=anymovie-2012

localhost/Songs/anymovie-2012

但是当我尝试

localhost/Songs/<anytext>

例如。

localhost/Songs/test

然后它也调用了songs.php,而不是抛出找不到页面的错误。

如果数据库中不存在最后一个关键字,如何抛出未找到页面错误。

对于解决方案,

我应该在songs.php 文件或.htaccess 文件中编码吗?我需要做什么类型的代码?

4

1 回答 1

1

您需要更具体地说明应重定向的格式;例如

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} ^[a-z0-9]+\-[0-9]{4}(\-[a-z0-9]+)?$
RewriteRule ^/?Songs/(.*)$ /Songs/Songs.php?movie=$1 [L,QSA]

应该管用。新行需要一个标题破折号年份,其中标题只能包含小写字母和数字,年份必须是四个数字,后跟可选的字母和数字字符串。

于 2012-11-29T17:14:28.873 回答