views:

216

answers:

1

I am reworking my website, going to be renaming a lot of directories, and need a simple way to write my .htaccess redirects for all of those pages. I am hoping for a solution that does not include a very long list of files. My .htaccess file is huge as it is.

Thanks in advance!

Lady Aleena

A: 

You can use mod_alias or mod_rewrite for your redirecting. mod_rewrite works with regular expressions and mod_alias can work on both regular expression and path prefixes.

Here are some examples for when you want to rewrite /foo/… to /bar/…:

# mod_alias
# path prefix
Redirect 301 /foo /bar
# regular expression
RedirectMatch 301 ^/foo/(.*) /bar/$1

# mod_rewrite
RewriteEngine on
RewriteRule ^foo/(.*) /bar/$1 [L,R=301]

Note that mod_alias and mod_rewrite have different requirements for their regular expressions patterns. mod_alias does always require the full URL path. But with mod_rewrite it depends on whether you use it in a .htaccess file or in the server configuration/virtual host section. In a .htaccess file, you need to write the pattern without the per-directory path prefix (in case of the document root just /, in case of /quux/ it’s /quux/).

Gumbo
I can't get the formatting to work, sorry.I did something wrong when using the above. I wrote... Redirect 301 /fantasy/v /fantasy/opinions RedirectMatch 301 ^/fantasy/v/(.*) /fantasy/opinions/$1but that caused a internal server error for my whole site. Then I tried this... Redirect 301 http://www.xecu.net/fantasy/v http://www.xecu.net/fantasy/opinions RedirectMatch 301 http://www.xecu.net/fantasy/v(.*) http://www.xecu.net/fantasy/opinions$1That didn't cause an error, but didn't work. What did I do wrong?
Lady Aleena