重写友好 URL,不同的模式
Rewrite friendly URL,differents patterns
我有以下重写规则
<filesMatch "^(member)$">
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/(.*)/(.*)/(.*)$ /member-profile.php?ID= [L]
</filesMatch>
<filesMatch "^(community-events)$">
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/(.*)/(.*)/(.*)/(.*)$ /community-events.php?ID= [L]
</filesMatch>
这显然是重写
mydomain.com/comunity-events/category/id/name
至此
mydomain.com/comunity-events.php?myvariables
现在,我想要一个没有起始 "folder" 的新重定向,就像这样
mydomain.com/business-category/business-name
到
mydomain.com/business-profile.php?variables
在给定当前配置的情况下,是否有可能不对每个类别名称进行重定向?
您甚至不需要 filesMatch
指令,因为您可以匹配 RewriteRule
本身的起始部分。
您可以用这些规则替换您的 .htaccess:
Options +FollowSymlinks -MultiViews
RewriteEngine On
# handle /member/...
RewriteRule ^/?(member)/(.*)/(.*)$ /member-profile.php?ID= [L,QSA,NC]
# handle /community-events/...
RewriteRule ^/?(community-events)/(.*)/(.*)/(.*)$ /community-events.php?ID= [L,QSA,NC]
# handle /business-category/business-name
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.*)/(.*)$ business-profile.php?name= [L,QSA]
我有以下重写规则
<filesMatch "^(member)$">
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/(.*)/(.*)/(.*)$ /member-profile.php?ID= [L]
</filesMatch>
<filesMatch "^(community-events)$">
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^/(.*)/(.*)/(.*)/(.*)$ /community-events.php?ID= [L]
</filesMatch>
这显然是重写
mydomain.com/comunity-events/category/id/name
至此
mydomain.com/comunity-events.php?myvariables
现在,我想要一个没有起始 "folder" 的新重定向,就像这样
mydomain.com/business-category/business-name
到
mydomain.com/business-profile.php?variables
在给定当前配置的情况下,是否有可能不对每个类别名称进行重定向?
您甚至不需要 filesMatch
指令,因为您可以匹配 RewriteRule
本身的起始部分。
您可以用这些规则替换您的 .htaccess:
Options +FollowSymlinks -MultiViews
RewriteEngine On
# handle /member/...
RewriteRule ^/?(member)/(.*)/(.*)$ /member-profile.php?ID= [L,QSA,NC]
# handle /community-events/...
RewriteRule ^/?(community-events)/(.*)/(.*)/(.*)$ /community-events.php?ID= [L,QSA,NC]
# handle /business-category/business-name
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.*)/(.*)$ business-profile.php?name= [L,QSA]