Forum Moderators: phranque

Message Too Old, No Replies

If file is not index then

         

MrGecko

12:46 am on Oct 7, 2007 (gmt 0)

10+ Year Member



How can I do some thing such as redirect if the file location is not / can I do this
<IF %{SCRIPT_NAME} is not />
</IF>
or how can i do that

jdMorgan

3:25 am on Oct 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you mean that literally, then no, that won't work. However, such a function is available in Apache mod_rewrite [httpd.apache.org], using the RewriteCond directive to examine the requested URL-path (or the filename that that URL-path resolves to) and conditionally invoke a RewriteRule.

For more information, see the documents cited in our forum charter [webmasterworld.com] and the tutorials in the Apache forum section of the WebmasterWorld library [webmasterworld.com].

Jim

MrGecko

4:01 am on Oct 7, 2007 (gmt 0)

10+ Year Member



Is it possible to redirect for an example if the url is http://www.example.com/ than it won't redirect but if it is http://www.example.com/whatever it would?
if you don't understand than if you go to the index page it wont redirect but if you go to anything else it well.
because i have a web site that i change the domain name and i want the index page to tell them that the address has been changed and if they go any where beyond the index page it will redirect to the file on the new domain name.

Mr. Gecko

jdMorgan

11:48 am on Oct 7, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes, it's not only possible, it's actually fairly easy. Please read the documentation cited above for more info.

Jim

MrGecko

5:11 pm on Oct 7, 2007 (gmt 0)

10+ Year Member



Can you point me to the part that tells you how i can't find it and it a big document

jdMorgan

1:47 pm on Oct 8, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well, if you want to be successful using mod_rewrite, you need to read all of the cited documents (several times), and learn all about it. Understand that mod_rewrite is a very powerful tool and it can be dangerous: You are changing your server configuration here, not just making a small tweak to a server application. Side-effects of even the smallest errors in planning, coding, and/or implementation can nuke your site from the search engines, and may result in intermittent errors that are almost impossible to find.

That said, here is what you seem to be looking for. This comes with limited support, since it won't be possible to discuss problems effectively if you're not yet familiar with the concepts and terms.


RewriteCond $1 !^(index\.php)?$
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

I assume that your index page filename is "index.php" here. If not, adjust the RewriteCond pattern to suit. The pattern, as written, recognizes either "/index.php" or "/" as exceptions to the redirect.

Note that this code will redirect requests for robots.txt, labels.rdf, w3c/p3p.xml, images, CSS files, external JavaScript files, etc. Since those files are not "/" or "index.php", they will be redirected as you have specified.

Jim