douxi4114 2016-07-14 10:13 采纳率: 100%
浏览 27
已采纳

.htaccess将第二个参数重写到目录

I would like the last parameter/directory from the following urls:

http://example.com/movies/randomMovie
http://example.com/books/randomBook

to be passed like following:

http://example.com/movies.php?=randomMovie
http://example.com/books.php?=randomBook

I have tried the following:

RewriteEngine on
RewriteRule ^([^/d]+)/?$ movies.php?=$1 [QSA]
RewriteRule ^([^/d]+)/?$ books.php?=$1 [QSA]

But that overwrites the rule for (movies.php).

How do I achieve this in .htaccess?

  • 写回答

2条回答 默认 最新

  • doukangbin9698 2016-07-14 10:14
    关注

    Your rule is not matching /movies/ and /books/, you can use this rule:

    RewriteEngine on
    
    RewriteRule ^movies/([^/]+)/?$ movies.php?=$1 [L,QSA,NC]
    RewriteRule ^books/([^/]+)/?$ books.php?=$1 [L,QSA,NC]
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?