Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7
  1. #1
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts

    How do I redirect all files with a specific extension?

    How can I redirect all files ending in ".php" and within certain folders to my index?

    Code:
    http://www.cineweekly.com/sunday/file.php
    http://www.cineweekly.com/monday/file.php
    Redirects to:

    Code:
    http://www.cineweekly.com/

  • #2
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Code:
    RedirectRule ^(sunday|monday)/.*\.php$ [R=301]

  • #3
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    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:

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

  • #4
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    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.

  • #5
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by Cags View Post
    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.

  • #6
    New Coder
    Join Date
    Jul 2011
    Posts
    67
    Thanks
    0
    Thanked 13 Times in 13 Posts
    Code:
    RewriteRule ^(sunday|monday|tuesday|wednesday|thursday|friday|saturday)/.*\.php$ / [R=301]

  • Users who have thanked Cags for this post:

    cineweekly.com (08-10-2011)

  • #7
    Regular Coder cineweekly.com's Avatar
    Join Date
    Aug 2010
    Posts
    485
    Thanks
    14
    Thanked 3 Times in 3 Posts
    Awesome thank you! I'll learn from this.

    Any help on this thread?: My .htaccess is getting bad flag delimiters on hotlink protection


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •