.htaccess - 301 Redirects, and the correct regex to go with it -


I have many URLs that I want to redirect to a single place, but these are dynamic URLs.

The structure is something like this:

  http://www.mysite.com/declaration/list [query_string]  

I think That would be ideal for this situation to use some regex in my .htaccess file to redirect all these links to the homepage homepage.

I was thinking that someone regex me for this situation so far, I have this, but it does not work:

  rewrite% {QUERY_STRING} ^ (. *) $ Rewrite rule / announcement / list $ http: //www.mysite com / $ [r = 301, l]  

My regex is weak to say the least I want to learn something else.

Thanks in advance Tom

Since you are using mod_rewrite in the .htaccess file You have to remove the relevant path prefix from the pattern then try it:

  rewrite %% {QUERY_STRING} ^ (. *) $ Rewrite ^ announcement / list $ http: // www. Example.com/ [R = 301, L]  

and . * will match the any string, your RewriteCond command will not have any additional use:

  rewrite ^ declaration / List $ http://www.example.com/ [R = 301, L]  

And if you do not want to query automatically be attached to the new URL, Specify an empty query in the replacement:

  rewrite ^ announcement / list $ http://www.example.com/? [R = 301, L]  

Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -