1

我有一个位于文件夹“/mixtapes/”中的 .htaccess 文件,我正在尝试获取mydomain.com/music/downloads/mixtapes/this-title/id要执行的 URLmydomain.com/music/downloads/mixtapes/item.php?title=variable1&id=variable2

我目前有下面的方法有点工作,但它只使用id,我需要两个变量(../mixtapes/title/id),由“/”分隔,并且由于某种原因,下面的代码在“/mixtapes/”中的索引页面“不起作用。我难住了!我对此有些陌生,非常感谢任何帮助!

顺便说一句,在我的索引页面上,传递到item.php页面的 url 被重写为<a href="title/id">我似乎无法让它以item.php?title=a&id=b格式正确执行mixtapes/title/id

当前的 htaccess 文件位于“/mixtapes/”

# turn mod_rewrite engine on 
RewriteEngine On

# rewrite all physical existing file or folder
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d

# allow things that are certainly necessary
RewriteCond %{REQUEST_URI} "/css/" [OR]
RewriteCond %{REQUEST_URI} "/images/" [OR]
RewriteCond %{REQUEST_URI} "/images/" [OR]
RewriteCond %{REQUEST_URI} "/javascript/"

# rewrite rules
RewriteRule ^mixtapes/item.php(.*) - [L]
RewriteRule ^(.*) item.php?id=$1 [QSA]
4

1 回答 1

0

您的 .htaccess 中的评论实际上是错误的

# turn mod_rewrite engine on 
RewriteEngine On

# if requested URL is NOT a existing file  
RewriteCond %{REQUEST_FILENAME} !-f [OR]
# or if requested URL is NOT a directory
RewriteCond %{REQUEST_FILENAME} !-d

# CSS, images, JavaScript are files and we will never pass this point when those are requested, next rules can be skipped

# rewrite rules
# rewrite /mixtapes/title/id to item.php?title=title&id=id
Rewrite ^mixtapes/([^/]+)/([0-9]+)  item.php?title=$1&id=$2   [L]

# catch all other requests and handle them ( optional, default would be 404 if not a physically existing file )
Rewrite (.*) index.php  [L,QSA]

我假设您的 id 是一个数值。请注意在 php.ini 中使用标题。不要直接输出,但您可以使用它来验证您的 URL 并重定向错误的标题/ID 组合

于 2012-11-11T22:08:08.460 回答