简体   繁体   中英

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.

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/

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/ . Now, in your bootstrap (index.php) you can get the request URI and process the action accordingly.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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