Hi all!
How do I get rid of the index.php file in the URL? Currently my site works either way:
http://domain.com/index.php/my/page http://domain.com/my/page
The second one is what I want. What kind of rule do I need to replace the index.php from URLs?
So,
http://domain.com/index.php => http://domain.com/ http://domain.com/index.php/my/page => http://domain.com/my/page
I'm using IIS so it requires it's own way of creating rewrite rules, but the Apache way is completely fine. IIS has an import function for those which seems to work just fine.
Thanks,
Mikko
Let me understand... You imported some mod_rewrite rules inside IIS and now the site works either with and without "index.php", is that right? Well, that's the usual behavior. So, what do you want the webserver to do when it first receives a request with "index.php"? Do you want it to send a redirect to the same url without "index.php"? Or do you want it to send an HTTP error code with error message?
popolla said:
Let me understand... You imported some mod_rewrite rules inside IIS and now the site works either with and without "index.php", is that right? Well, that's the usual behavior. So, what do you want the webserver to do when it first receives a request with "index.php"? Do you want it to send a redirect to the same url without "index.php"? Or do you want it to send an HTTP error code with error message?
I want to redirect to a route without index.php
With Apache you would use the R flag.
You can try adding something like this before the other rewrite rules (to be left untouched):
RewriteRule ^index\.php/(.*)$ $1 [R=301,L]
That may require some tuning, please search the web.
popolla said:
With Apache you would use the R flag.
You can try adding something like this before the other rewrite rules (to be left untouched):RewriteRule ^index.php/(.*)$ $1 [R=301,L]
That may require some tuning, please search the web.
Great, this almost fixes the whole problem.
It redirects domain.com/index.php/my/page to domain.com/my/page but I'd also want to redirect domain.com/index.php to domain.com/ without the index.php
RewriteRule ^index.php/?(.*)$ $1 [R=301,L]
popolla said:
RewriteRule ^index.php/?(.*)$ $1 [R=301,L]
Thanks a lot for this one!
In IIS it is
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^index.php/?(.*)$" ignoreCase="false" />
<action type="Redirect" redirectType="Permanent" url="{R:1}" />
</rule>
</rules>
</rewrite>
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community