繁体   English   中英

.htaccess中的URL重写无法正常工作

[英]URL rewriting in .htaccess doesn't works as it should

我目前正在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 / (确实包含与原始URL完全相同的GET参数)。

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

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

当我在浏览器中编写第二个URL时,它显示了一个空白页面,根本没有代码行。 我的第一个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]

在此先感谢您的帮助 !

只是将这段代码粘贴到您的.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]

希望它将成功。

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

之前:

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

之后:

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

现在它可以工作了,但是我仍然遇到此处所述的多个连字符的问题: .htaccess中的多个连字符处理(URL重写)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM