Forum Moderators: phranque

Message Too Old, No Replies

using htaccess to send all traffic to index.php?

         

DiscoStu

10:46 pm on Jan 24, 2011 (gmt 0)

10+ Year Member



Trying to redirect all traffic, so any url existing or not, will go to index.php but I'm having problems. Does anyone know how to do it?

Edit:

Found a solution that seems to be working:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteRule . /index.php [L]
</IfModule>

RewriteRule !^index\.php$ /index.php [L,R=302]

g1smd

12:35 am on Jan 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



The code rewrites all requests to the index.php script. It should not do so for images, stylesheets, scripts or robots.txt.

The redirect code will also redirect requests for images, stylesheets, scripts, and robots.txt - all of which should NOT be redirected. You should exclude those types of request from being redirected.

There are other problems. Listing a redirect after an internal rewrite will expose internal server filepaths back out on to the web. Always list all external redirects before any internal rewrites to avoid this.

Using a 302 redirect also gives your site "infinite URL space" and may be a signal of "low technical quality" as far as some search engines are concerned.

What are you actually trying to achieve here? There may be a completely different solution at hand.

DiscoStu

6:21 pm on Jan 25, 2011 (gmt 0)

10+ Year Member



I just want all old links to urls on the domain to redirect to index.php. I've removed every page except for the index page, and I wand all old pages to go to the homepage (no 404s, no error message)

g1smd

7:51 pm on Jan 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



That definitely is a "signal of low technical quality" as far as search engines are concerned.

Pages that no longer exist should return a 404 status, not a 301 status. The 404 error page should contain a message explaining everything.

If against all advice you proceed with this, do not redirect URL requests for images, stylesheets, scripts, robots.txt, etc.

jdMorgan

5:54 pm on Feb 7, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



And use a 301 redirect, unless you plan to "bring these URLs back to life" in future.

Jim