Weird problem with 301 redirects

by 5 replies
6
Have a new site designed but the weird thing is a few pages that are indexed in Google with the trailing slash at the end either come up as 404 or when I did a redirect checker they are redirecting to /usr/local/apache/htdocs/company is just one example.

Anyone know what could cause it redirecting to the actual directory? It is weird because most of all the website works its only a problem following links indexed in Google.

This is the current redirect rules:

<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteRule ^([^\.]+?)/?$ $1.php [NC,L]
</IfModule>
#programming #301 #problem #redirects #weird
  • Just an update on this problem, we got most pages to work after some tweaks when users are on the website, the only problem exists "Trailing Slash" if you add a trailing slash to any URL it will show the directory contents, I added the rewrite rule to redirect trailing slash to the URL without it but its not working.

    here is the code im using:

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([^/]+)/$ $1 [R=301,L]
  • Can you post the link?
    I need to see the actual problem.

    Is it an html site? or PHP site?
    And what are you trying to do? Redirect
    domain.com/page/ to domain.com/page
    domain.com/page2/ to domain.com/page2
    ?
    • [1] reply
    • I will PM you the URL.

      For the problem here it is in summary which I found out just recently:

      The site is in PHP, all top level categories or pages are in .php format and those files are located in the root directory (basically public html)... But there are also subfolders with the same name as some of the top pages.

      here is an example:

      company.php currently redirects to domain.com/company
      /company/ is a subfolder which inside has subpages like page1.php, page2.php so if you go to domain.com/company/page1.php that will load.

      The issue is if you go to the url domain.com/company/ that creates a problem because it is loading the subdirectory either showing a directory contents or redirects to a weird URL.

      I want domain.com/company/ and all other subdirectories to redirect to the corrosponding .php located in the root domain (or basically the top level page like domain.com/company/ -----> domain.com/company).
  • Try to add
    Code:
    Options -Indexes
    on your .htaccess file. Outside any IF statement.

    I don't know with other programmers, but for me, it's a bad idea to have multiple PHP files inside inside a folder, or subfolder that needs to be run/accessed independently. /products/ category may contain other PHP files but only for code modulation. Not for multiple page/site views on the same folder/directory.

    Also check your file permissions. Most PHP files only needs to be set as 655 permission.
  • Thanks, I will pass along that info to the web developer, but I did try to add Options - Indexes dont think that changed anything that I can see.

    I also tried to make a manual 301 redirect for a specific page like /products/ to redirect to the right page without trailing slash but that just causes issues.

Next Topics on Trending Feed

  • 6

    Have a new site designed but the weird thing is a few pages that are indexed in Google with the trailing slash at the end either come up as 404 or when I did a redirect checker they are redirecting to /usr/local/apache/htdocs/company is just one example. Anyone know what could cause it redirecting to the actual directory? It is weird because most of all the website works its only a problem following links indexed in Google.