Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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
Regex URL重写–;第一个值不为';行不通_Regex_Apache_.htaccess_Mod Rewrite_Url Rewriting - Fatal编程技术网

Regex URL重写–;第一个值不为';行不通

Regex URL重写–;第一个值不为';行不通,regex,apache,.htaccess,mod-rewrite,url-rewriting,Regex,Apache,.htaccess,Mod Rewrite,Url Rewriting,我正在尝试使用以下方法创建友好的URL: Options +Indexes Options +FollowSymLinks Options -MultiViews <IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule

我正在尝试使用以下方法创建友好的URL:

Options +Indexes
Options +FollowSymLinks 
Options -MultiViews

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^([^/]*)/([^/]*)/([^/]*)/?$ /index.php?lang=$1&page=$2&subpage=$3 [L,QSA]
</IfModule>
选项+索引
选项+FollowSymLinks
选项-多视图
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写规则^([^/]*)/([^/]*)/([^/]*)/?$/index.php?lang=$1&page=$2&subpage=$3[L,QSA]
尝试时一切正常:

www.mydomain.com/en/my-page/

www.mydomain.com/en/my-page/my-subpage/

但是,当我尝试此操作时,出现404错误:

www.mydomain.com/en/

我一直在努力理解这个问题。 提前谢谢

-编辑- 阿努巴瓦的解决方案非常有效。除此之外,如果您需要可选参数

Options +Indexes
Options +FollowSymLinks 
Options -MultiViews

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteCond %{REQUEST_FILENAME} !-f

    RewriteCond %{REQUEST_URI}  ^/([^/]+)/?([^/]*)?/?([^/]*)?/?([^/]*)?/?   [NC]
    RewriteRule .*    index.php?lang=%1&page=%2&subpage=%3&anotherkey=%4  [L]
</IfModule>
选项+索引
选项+FollowSymLinks
选项-多视图
重新启动发动机
重写基/
重写cond%{REQUEST_FILENAME}-D
重写cond%{REQUEST_FILENAME}-F
重写第二个%{REQUEST_URI}^/([^/]+)/?([^/]*)?/?([^/]*)?/?([^/]*)?/?([^/]*)?/?[北卡罗来纳州]
重写规则。*index.php?lang=%1&page=%2&subpage=%3&anotherkey=%4[L]
让它像这样:

Options +Indexes
Options +FollowSymLinks 
Options -MultiViews

<IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteBase /
    RewriteCond %{REQUEST_FILENAME} -d [OR]
    RewriteCond %{REQUEST_FILENAME} -f
    RewriteRule ^ - [L]

    RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ /index.php?lang=$1&page=$2&subpage=$3 [L,QSA]
    RewriteRule ^([^/]+)/([^/]+)/?$ /index.php?lang=$1&page=$2 [L,QSA]
    RewriteRule ^([^/]+)/?$ /index.php?lang=$1 [L,QSA]
</IfModule>
选项+索引
选项+FollowSymLinks
选项-多视图
重新启动发动机
重写基/
RewriteCond%{REQUEST_FILENAME}-d[或]
RewriteCond%{REQUEST_FILENAME}-f
重写规则^-[L]
重写规则^([^/]+)/([^/]+)/([^/]+)/?$/index.php?lang=$1&page=$2&subpage=$3[L,QSA]
重写规则^([^/]+)/([^/]+)/?$/index.php?lang=$1和page=$2[L,QSA]
重写规则^([^/]+)/?$/index.php?lang=$1[L,QSA]