Forum Moderators: phranque

Message Too Old, No Replies

Rewrite ->Redirect all .php except a subfolder

Redirect all .php except a subfolder

         

havanaclubcola

4:35 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



I want to redirect all the request of php pages to my index.html, but I need that my ao/BackOffice stay accessible.

I tried this but it is not working:

RewriteEngine on
RewriteCond %{REQUEST_URI} ao/BackOffice$
RewriteRule ^(.*)\.php$ [example.com...] [R=302,L]

Someone can help me?

[edited by: jdMorgan at 5:34 pm (utc) on Sep. 22, 2004]
[edit reason] Removed specifics per TOS [/edit]

jdMorgan

5:41 pm on Sep 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



havanaclubcola,

Welcome to WebmasterWorld! Please review our Terms of Service and the Apache Forum charter.

The problem is that your code says to do the redirect *IF* the requested page matches ao/BackOffice. What you probably want to do is to redirect if the requested page *DOES NOT* match ao/BackOffice. In mod_rewrite, the negation operator is "!", so just add that to your RewriteCond:


RewriteEngine on
RewriteCond %{REQUEST_URI} [b]![/b]ao/BackOffice
RewriteRule \.php$ http://example.com/ao/index.html [R=302,L]

More information is available through the links in our charter [webmasterworld.com].

Jim

havanaclubcola

6:41 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



Hi Jim,
sorry for the mistake about the domain name... it happens.

Yes, you are right I was wrong, but there was another mistake.

this is the new working rule:

RewriteCond %{REQUEST_URI}!^.*backoffice.*

Anyway, there is no way to debug or test the rewrite rules?
If there is it can be great!

jdMorgan

7:36 pm on Sep 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



There is no need to add "^.*" to the beginning of the pattern, or ".*" to the end. Adding that does not change anything, except to slow down your server. Again, see the links in our charter -- specifically, the regular expressions tutorial.

Do you have any other working RewriteRules? If not, then you may need to add a line to the code:


[b]Options +FollowSymLinks[/b]
RewriteEngine on
RewriteCond %{REQUEST_URI} !BackOffice
RewriteRule \.php$ http://example.com/ao/index.html [R=302,L]

Enabling FollowSymLinks or SymLinksIfOwnerMatch is required by mod_rewrite.

There is no mod_rewrite "debugger." However, your server error logs will often contain information that is useful in getting your code to work.

Jim

havanaclubcola

10:41 pm on Sep 22, 2004 (gmt 0)

10+ Year Member



Many thanks Jim, you where right!

Sorry, but mod_rewrite it's a really hard to understand topic...