...

View Full Version : How do I redirect all files with a specific extension?



cineweekly.com
08-06-2011, 07:01 AM
How can I redirect all files ending in ".php" and within certain folders to my index?


http://www.cineweekly.com/sunday/file.php
http://www.cineweekly.com/monday/file.php

Redirects to:


http://www.cineweekly.com/

Cags
08-06-2011, 07:25 AM
RedirectRule ^(sunday|monday)/.*\.php$ [R=301]

cineweekly.com
08-06-2011, 10:17 PM
I can't get it to work. I tried using RewriteCond too which is what the rest of my htaccess uses (used cPanel for most of it). Can you help clean this up, here's what I'm attempting:



# Sends all old format pages to the homepage.
RewriteCond ^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/.*\.php$
RewriteRule ^/?$ "http\:\/\/www\.cineweekly\.com\/" [R=301]

Cags
08-07-2011, 07:54 AM
You have to match against something in the RewriteCond, what you have is invalid syntax. You are attempting to match the URI which means if you had to do it with a Cond you would require...

CODE]RewriteCond %{REQUEST_URI} ^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/.*\.php$[[/CODE]

The reason it's not working is because in your RewriteRule you are matching against a request to root (an optional forward slash, which is stripped off anyway if your rules are in your .htaccess file). You could replace the pattern for the rule with .*, but this seems a little redundant, since you are pattern matching the URI with both the Cond and the Rule. One thing to bare in mind is (assuming I'm remember correctly), the REQUEST_URI string when used in a RewriteCond always begins with a forward slash, so you need to take that into account with your pattern. Whilst the RewriteRule matches against the REQUEST_URI, it is a modified version of the string that is relative to the location of the .htaccess file.

cineweekly.com
08-10-2011, 03:31 AM
You have to match against something in the RewriteCond, what you have is invalid syntax. You are attempting to match the URI which means if you had to do it with a Cond you would require...

CODE]RewriteCond %{REQUEST_URI} ^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/.*\.php$[[/CODE]

The reason it's not working is because in your RewriteRule you are matching against a request to root (an optional forward slash, which is stripped off anyway if your rules are in your .htaccess file). You could replace the pattern for the rule with .*, but this seems a little redundant, since you are pattern matching the URI with both the Cond and the Rule. One thing to bare in mind is (assuming I'm remember correctly), the REQUEST_URI string when used in a RewriteCond always begins with a forward slash, so you need to take that into account with your pattern. Whilst the RewriteRule matches against the REQUEST_URI, it is a modified version of the string that is relative to the location of the .htaccess file.

I'm so lost, I don't know anything about Apache. Could you give me the final line(s) of code to copy and paste? I'll try to reverse engineer it afterwards so I can learn instead of just mooching.

Cags
08-10-2011, 08:44 AM
RewriteRule ^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/.*\.php$ / [R=301]

cineweekly.com
08-10-2011, 09:50 PM
Awesome thank you! I'll learn from this.

Any help on this thread?: http://www.codingforums.com/showthread.php?t=234002



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum