Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 重写友好的URL,不同的模式_.htaccess_Mod Rewrite_Url Rewriting_Mod - Fatal编程技术网

.htaccess 重写友好的URL,不同的模式

.htaccess 重写友好的URL,不同的模式,.htaccess,mod-rewrite,url-rewriting,mod,.htaccess,Mod Rewrite,Url Rewriting,Mod,我有以下重写规则 <filesMatch "^(member)$"> Options +FollowSymlinks RewriteEngine on RewriteRule ^/(.*)/(.*)/(.*)$ /member-profile.php?ID=$2 [L] </filesMatch> <filesMatch "^(community-events)$"> Options +FollowSymlinks

我有以下重写规则

<filesMatch  "^(member)$">
    Options +FollowSymlinks
    RewriteEngine on

    RewriteRule ^/(.*)/(.*)/(.*)$  /member-profile.php?ID=$2 [L]
</filesMatch>

<filesMatch  "^(community-events)$">
    Options +FollowSymlinks
    RewriteEngine on

    RewriteRule ^/(.*)/(.*)/(.*)/(.*)$  /community-events.php?ID=$3 [L]
</filesMatch>
对此

mydomain.com/comunity-events.php?myvariables
现在,我想要一个新的重定向,它没有一个开始的“文件夹”,就像这样

mydomain.com/business-category/business-name


考虑到当前的配置,这是否可能,而无需对每个类别名称进行重定向?

您甚至不需要
文件匹配
指令,因为您可以在
重写规则
本身中匹配起始部分

您可以使用以下规则替换.htaccess:

Options +FollowSymlinks -MultiViews
RewriteEngine On

# handle /member/...
RewriteRule ^/?(member)/(.*)/(.*)$ /member-profile.php?ID=$2 [L,QSA,NC]

# handle /community-events/...
RewriteRule ^/?(community-events)/(.*)/(.*)/(.*)$ /community-events.php?ID=$3 [L,QSA,NC]

# handle /business-category/business-name
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.*)/(.*)$ business-profile.php?name=$2 [L,QSA]

您甚至不需要
filesMatch
指令,因为您可以在
RewriteRule
本身中匹配起始部分

您可以使用以下规则替换.htaccess:

Options +FollowSymlinks -MultiViews
RewriteEngine On

# handle /member/...
RewriteRule ^/?(member)/(.*)/(.*)$ /member-profile.php?ID=$2 [L,QSA,NC]

# handle /community-events/...
RewriteRule ^/?(community-events)/(.*)/(.*)/(.*)$ /community-events.php?ID=$3 [L,QSA,NC]

# handle /business-category/business-name
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.*)/(.*)$ business-profile.php?name=$2 [L,QSA]
Options +FollowSymlinks -MultiViews
RewriteEngine On

# handle /member/...
RewriteRule ^/?(member)/(.*)/(.*)$ /member-profile.php?ID=$2 [L,QSA,NC]

# handle /community-events/...
RewriteRule ^/?(community-events)/(.*)/(.*)/(.*)$ /community-events.php?ID=$3 [L,QSA,NC]

# handle /business-category/business-name
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/?(.*)/(.*)$ business-profile.php?name=$2 [L,QSA]