tags:

views:

29

answers:

1

I searched a ton for this, everyone is either directing from root to sub-directory or known /folder to root.

Here is what I am trying to do

  • I have hundreds of dynamically created URLs - foo.com/123, foo.com/contact, etc.
  • I'd like to redirect all those URLs (don't know all of them, just know there are a-z or 1-9) to just foo.com.

Any ideas?

A: 

Sounds like you need mod_rewrite to rewrite a URL for you. There are tons of mod_rewrite examples on the Internet to do exactly what you need. The rough idea is:

RewriteRule [match expression] [new location expression] [options]

The following StackOverflow questions may help:

  1. Redirecting all traffic to a specific subdomain using modrewrite
  2. More .htaccess discussions

Allowing you to run a regular expression match against a URL and rewrite it using groups into a new URL. If your HTTP server allows mod_rewrite directives in .htaccess and you have the module installed in the server (most Linux distros and WAMP installs do by default).

First

RewriteEngine On  

Then

   RewriteRule ^/(.*)$ / [L]

or

RewriteRule ^/(.*)$ /?page=$1 [L]

If you want to know where they came from

Aiden Bell
Thanks, Aiden. That didn't work, just stays there and returns a 404.Here is what I have so far:<code>RewriteEngine onRewriteCond %{HTTP_HOST} ^foo.com [NC]RewriteRule ^(.*)$ http://www.foo.com/$1 [L,R=301]#redirects index.html to rootRewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(([^/]+/)*)index\.html\ HTTP/ RewriteRule ^(.*)index.html$ http://www.foo.com/$1 [R=301,L]#redirects /everything to rootRewriteRule ^/(.*)$ / [L]</code>
Jason C
I have been trying to paste that code properly in this comment. Tried spaces, <code> block, everything.
Jason C