mod rewrite - URL redirect with Nested RewriteCond in .htaccess -
i'm migrating old url:
example.com/video?id=40
to new one:
example.com/video/name-of-video
but them don't share field, can't make single rule , have write rewritecond every video have:
rewritecond %{query_string} ^id=1$ rewriterule (.*) http://www.example.com/video/name-of-video? [r=301,l] rewritecond %{query_string} ^id=2$ rewriterule (.*) http://www.example.com/video/name-of-video? [r=301,l] rewritecond %{query_string} ^id=3$ rewriterule (.*) http://www.example.com/video/name-of-video? [r=301,l] rewritecond %{query_string} ^id=5$ ...
so have more 6000 rewritecond slows web. want achieve check if url has query string 'id=(.*)' , if has it, check id has redirect correct video. want like:
# if rewritecond %{query_string} ^id=(.*)$ # rewritecond %{query_string} ^id=1$ rewriterule (.*) http://www.example.com/video/name-of-video? [r=301,l] rewritecond %{query_string} ^id=2$ rewriterule (.*) http://www.example.com/video/name-of-video? [r=301,l] rewritecond %{query_string} ^id=3$ rewriterule (.*) http://www.example.com/video/name-of-video? [r=301,l] rewritecond %{query_string} ^id=5$ # else nothing
so on every load page, checks 1 rewritecond instead of 6000, avoiding slow down web
you can keep first rule as bail out rule:
# if rewritecond %{query_string} !^id=\d+$ rewriterule ^ - [l]
this not evaluate rule below if ?id=<number>
not present in query string.
Comments
Post a Comment