.htaccess中的网址重写无法正常运行

时间:2018-11-12 10:26:30

标签: php .htaccess url-rewriting

我目前正在WampServer(本地)上用PHP和MySQL编写自己的网站。我已经成功重写了一些URL。但是我遇到其中一个问题。

我想使用GET方法在页面上显示类别中列出的所有文章。目前,我有以下URL: http://localhost/actuco/cat.php?id=xpS3cc&slug=amerique-du-nord ,并且我想使用此URL并将其显示为 http://localhost/actuco/c-xpS3cc-amerique-du-nord/ (确实包含GET参数与原始URL相同。

我尝试使用.htaccess文件中的以下行执行此操作

RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2

当我在浏览器中写入第二个URL时,它显示了一个空白页面,根本没有代码行。我的第一个网址效果很好。

我真的迷路了,我真的不知道该如何解决。

这是我网站上使用的整个.htaccess文件(此文件中的所有其他URL重写都可以使用)。

Options +FollowSymlinks

RewriteEngine On

RewriteBase /actuco/
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_URI} /+[^\.]+$
#RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
RewriteRule ^([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/([^/]*)/$ article.php?lng=$1&yr=$2&mo=$3&dy=$4&slug=$5&total_slug=$6
#RewriteRule ^([^/]*)-([^/]*)-([^/]*)$ waluty.php?cur=$1&amt=$2&lang=$3
RewriteRule ^([^/]*)/([^/]*)$ url.php?mode=$1&u=$2
RewriteRule ^c-([^/]*)-([^/]*)/$ cat.php?id=$1&slug=$2
RewriteRule ^bio$ o.php [L]

预先感谢您的帮助!

2 个答案:

答案 0 :(得分:0)

只需将此代码保存在您的.htaccess文件中

DirectoryIndex index.php
RewriteEngine on
RewriteCond $1 !^(index\.php|images|css|js|robots\.txt|favicon\.ico)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ ./index.php?/$1 [L,QSA]

希望它会工作。

答案 1 :(得分:0)

解决了!只是忘了在此行中在$之前添加斜杠

之前:

RewriteRule ^([^/]*)/([^/]*)$ url.php?mode=$1&u=$2

之后:

RewriteRule ^([^/]*)/([^/]*)/$ url.php?mode=$1&u=$2

现在它可以工作了,但是我仍然对此处所述的多个连字符存在问题:Multiple hyphen handling in .htaccess (URL rewriting)