4

URLs are working fine in my application. I mean they are pretty URLs. Like http://www.example.com/ But it also works when you access the page with index.php like http://www.example.com/index.php, which I don't want because it is showing two links in sitemap for one page. One page without index.php and another with index.php. Demonstration of the sitemap is here https://www.xml-sitemaps.com/details-eln.6762418.html

Here is the .htaccess

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
2
  • 1
    Dropping the one you don't want from the sitemap seems like the easiest solution. Commented Sep 2, 2015 at 16:59
  • right. bt i want to fix it on the application side. Commented Sep 2, 2015 at 17:08

1 Answer 1

5

Put the following code :

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,7}\s/(.*)index\.php\sHTTP.*$
RewriteRule ^ /%1 [R=301,L]
Sign up to request clarification or add additional context in comments.

5 Comments

when i implemented the above code the issue with index.php is resolved but all the links are broken. any idea?
its in the root directory.
On local machine if i run localhost/myproject/index.php, it takes me back to localhost/xampp. Is it right? I mean it should take me back to localhost/myproject. what do u say?
its not working for other links. can u please paste full code for .htaccess file in ur answer.
What about NGinx?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.