简体   繁体   English

创建具有多个重写规则的友好URL?

[英]Create friendly URL with multiple rewrite rules?

RewriteEngine on

RewriteBase /school/courses/more-courses/courses-type/coursedetails/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule [^/]+ index.php [QSA,L]

So php is used to replace the /coursedetails/ part with the course name eg /school/courses/more-courses/courses-type/cooking/, and so the script above will redirect everything that doesn't exist to index.php. 因此,php用于将/ coursedetails /部分替换为课程名称,例如/ school / courses / more-courses / courses-type / cooking /,因此上面的脚本会将所有不存在的内容重定向到index.php。

What I want to do is create a friendly URL to map, for example, /school/courses/more-courses/courses-type/cooking/ to /school/courses/cooking/ 我想做的是创建一个友好的URL进行映射,例如/ school / courses / more-courses / courses-type / cooking /到/ school / courses / cooking /

Is this possible by adding an additional rewrite rule? 是否可以通过添加其他重写规则来实现?

RewriteRule ^/school/courses/more-courses/courses-type/cooking/$ /school/courses/cooking/ [R,L]

What about this: 那这个呢:

RewriteBase ^/school/courses/([a-z\-]+/){1,5}$

This allows you to have any URL while begins with /school/courses/ and then anything (1-5 times) in the pattern folder-name/ . 这样,您可以以/school/courses/开头的任何URL,然后以folder-name/模式的所有URL(1-5次)。 Now, in your bootstrap (index.php) you can get the request URI and process the action accordingly. 现在,在您的引导程序(index.php)中,您可以获取请求URI并相应地处理操作。

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

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