문제

From the following url:

localhost/videos/the-best-games

and a directory named "categories" with various files in it located in the same directory as .htaccess :

./games.txt
./sports.txt
./football.txt

How to use the url slug "the-best-games" to check these filenames in "categories"

./categories/the.txt
./categories/best.txt
./categories/games.txt

And rewrite the url using the first matching filename:

localhost/games/videos/the-best-games

OR

localhost/games/videos/the-best

Maybe based on these previous questions:

도움이 되었습니까?

해결책

This should work for you:

RewriteCond /path/to/categories/$1.txt -f
RewriteRule /videos/the-best-(.*)$ /$1/videos/the-best-$1 [R,L]

It will parse the rule and look for the-best-(whatever), take that value and examine the file system for the file at the absolute path to your categories. Then it will do the rewrite. If you want to remove the category from the end of the rewritten URL:

RewriteCond /path/to/categories/$1.txt -f
RewriteRule /videos/the-best-(.*)$ /$1/videos/the-best [R,L]
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top