Apacheã®RewriteRuleã§æ¤ç´¢æ¡ä»¶ã«^/ããããããªãå ´åãããçç±
Apacheã®RewriteRuleã§ã/hoge/é ä¸ã«ã¢ã¯ã»ã¹ããã£ãã http://example.jp/fuga/ ã«301ãªãã¤ã¬ã¯ããè¡ããã£ã¦ãªå¦çãæ¸ãå ´åãå é ã«/ãå¿ è¦ãªå ´åã¨å¿ è¦ãªãå ´åãããã
RewriteEngine on # ããã§ãããå ´åããã RewriteRule ^/hoge/(.*) http://example.jp/fuga/$1 [R=301,L] # ããæ¸ããªãã¨ãã¡ãªå ´åããã RewriteRule ^hoge/(.*) http://example.jp/fuga/$1 [R=301,L]
ãã®å
é ã«/ãå¿
è¦ä¸è¦ã®éãã¯ãªãã ãããªã¼ã¨æã£ã¦ããããå
æ¥çç±ãããã£ãã
Apacheã®ããã¥ã¡ã³ãã«ãã£ããæ¸ãã¦ãã£ãã
What is matched?
- In VirtualHost context, The Pattern will initially be matched against the part of the URL after the hostname and port, and before the query string (e.g. "/app1/index.html").
- In Directory and htaccess context, the Pattern will initially be matched against the filesystem path, after removing the prefix that led the server to the current RewriteRule (e.g. "app1/index.html" or "index.html" depending on where the directives are defined).
ã¤ã¾ããã£ãã説æããã¨ãããªæããã
- VirtualHostãã£ã¬ã¯ãã£ãã®å ´åã¯URLã®ãã¹ã対象ã¨ãªãå é ã«/ãã¤ã
- Directoryãã£ã¬ã¯ãã£ãã.htaccessã®å ´åã¯ãã®ãã£ã¬ã¯ããªããã®ç¸å¯¾ãã¡ã¤ã«ãã¹ã対象ã«ãªãå é ã«/ãã¤ããªã
ç¥ããªãã£ãããããããã¨ã ã£ãã®ãã
ã¡ãªã¿ã«VirtualHostå
ã«Directoryãã£ã¬ã¯ãã£ãã®ä¸ã§RewriteRuleãæ¸ããå ´åã¯å¾è
ã«ãªã£ãã
ã©ãã«æ¸ãã¦ã使ãããã¿ã¼ã³
ä¸è¨ãæèãã¦æ¸ãã¦ãããã®ã ããã§ããã°ãã¼ã¿ããªãã£ãèæ
®ãã¦ã©ãã«æ¸ãã¦ã使ããããã«æ¸ãããã
ãããã©ãæ¸ãããç§ã¯ãããªæãã§æ¸ãã¦ãã
RewriteEngine on RewriteRule ^/?hoge/(.*) http://example.jp/fuga/$1 [R=301,L]
?ãå
¥ãã¦ã©ã¡ãã§ããããããããã«ã
ããã«ã¨ã³ã³ã¼ããQueryStringããã¡ãã¨å¼ãç¶ãããã«ãããªãããããªæãã§ã
RewriteEngine on RewriteRule ^/?hoge/(.*) http://example.jp/fuga/$1 [R=301,L,QSA,NE]
ããã¯ãã¹ã¦ã®ãã¹ãå¥ãµã¤ãã«è»¢éããå ´åãåæ§ã«æ¸ããã
RewriteEngine on RewriteRule ^/?(.*) http://example.jp/$1 [R=301,L,QSA,NE]
å é ã®/ãé¤å¤ãããããã¦è»¢éå URLã®è¨è¿°ãç¾ããã§ããã