Regex 搜索引擎优化友好的URL';s至->;改写
我正在尝试优化我的URL 示例URL(我想要): 我想将其转换为: 我的.htaccess:Regex 搜索引擎优化友好的URL';s至->;改写,regex,apache,.htaccess,mod-rewrite,Regex,Apache,.htaccess,Mod Rewrite,我正在尝试优化我的URL 示例URL(我想要): 我想将其转换为: 我的.htaccess: <IfModule mod_rewrite.c> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.*)/(.*)/$ $1.php?l=$2 [L] RewriteCond %{REQUEST_FILENAME} !-
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/(.*)/$ $1.php?l=$2 [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/$ $1.php [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
# Proper regex -> ([a-zA-Z0-9_-]+)
</IfModule>
重新启动发动机
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)/(.*)/$$1.php?l=$2[l]
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^(.*)/$$1.php[L]
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则。index.php[L]
#正确的正则表达式->([a-zA-Z0-9_-]+)
我的挑战是:
1) 尾部斜杠:对于我的正则表达式,我必须有一个尾部斜杠。当我将正则表达式更改为read^(.*)/(.*)/?$
时,它会在变量末尾添加一个“.php”。而且,如果我将?
保持为关闭状态,则需要尾部斜杠,或者,它将解析为“index.php”结果
2) 在第二条重写规则中也是如此-斜杠=内部服务器错误之前有?
,没有?
=全部正常
所以现在一切都正常了,除了我必须有尾随斜杠
似乎我在这里遗漏了一些非常简单的东西-如果有人指出这一点,我将不胜感激。对于
^([^/]+)/([^/]+)/?$
和第二条规则^([^/]+)/?$
?