We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

htaccess strip "index_php?"

How Do I?

fensterbaby's avatar
fensterbaby
289 posts
2 years ago
fensterbaby's avatar fensterbaby

Sorry about accidental multiple posts…I can’t even access those now

trying to strip “index.php?” from urls. It pulls out index.php but leaves “?”

I tried to include htaccess code but attempt to use markdown failed. Any files I try to attach are “not allowed”

Why can’t these post fields just be rich text fields?

       
DigitalSpirit's avatar
DigitalSpirit
11 posts
2 years ago
DigitalSpirit's avatar DigitalSpirit

I would strip the htaccess code back to nothing first and then work from there. My guess is that it’s something on the server set up.

Follow the instructions here - https://docs.expressionengine.com/latest/installation/best-practices.html#removing-indexphp-from-your-urls and then once it’s working add the caching and redirects back in.

       
fensterbaby's avatar
fensterbaby
289 posts
2 years ago
fensterbaby's avatar fensterbaby

Here is one thing I tried with mixed result

RewriteRule (.?)index.php/(.*) /$1$2 [R=301,NE,L]

add [QSD] to RewriteRule

RewriteRule (.?)index.php/(.*) /$1$2 [R=301,NE,QSD,L]

This strips out the query string but alas it treats everything after the ? as query string. So..

https://www.trekalaska.com/index.php?/destinations/denali-state-park

becomes

https://www.trekalaska.com/

without the [QSD] it becomes

https://www.trekalaska.com/?/destinations/denali-state-park

query string disabled in CP

These links are old one that Google still checks so produces errors. Links with index.php not being generated by current site

       
Hop Studios's avatar
Hop Studios
481 posts
2 years ago
Hop Studios's avatar Hop Studios

Try this:

RewriteRule ^index.php$ %{QUERY_STRING} [R=301,NE,QSD,L]

This should match https://www.trekalaska.com/index.php?/destinations/denali-state-park

and return https://www.trekalaska.com/destinations/denali-state-park

Note that it will match ONLY index.php, not any sub-path, and also that if the query string has more fluff than just the EE segments, that’ll still be appended after the rewrite, which might not be what you want.

…I used this to help: https://htaccess.madewithlove.com/

       
fensterbaby's avatar
fensterbaby
289 posts
2 years ago
fensterbaby's avatar fensterbaby

OMG- that’s it!

Seems to be working perfectly. I have tried soooo many times to fix this. You are the first with a solution that works as intended.

Thanks for your help!

       
fensterbaby's avatar
fensterbaby
289 posts
2 years ago
fensterbaby's avatar fensterbaby

I spoke too soon :-(

https://www.trekalaska.com/index.php?/destinations/denali-state-park

returns

https://www.trekalaska.com/destinations/denali-state-park

which is perfect

However… https://www.trekalaska.com/index.php/destinations/denali-state-park

Returns https://www.trekalaska.com/index.php/destinations/denali-state-parks

and a 404 error

It strips out “index.php?” But not “index.php”

Also, a URL like https://www.trekalaska.com/?/destinations/denali-state-park

outputs no change and a 404

so am trying to strip out any of the following

“index.php” - “index.php?” - “?”

       
Rob Allen's avatar
Rob Allen
3,105 posts
2 years ago
Rob Allen's avatar Rob Allen

Have you removed index.php from Settings > URL and Path Settings

https://docs.expressionengine.com/latest/control-panel/settings/urls.html#website-index-page

       
fensterbaby's avatar
fensterbaby
289 posts
2 years ago
fensterbaby's avatar fensterbaby

Yes. That was removed in settings.

It’s getting rid of “index.php?” or “?” that is a problem

https://www.trekalaska.com/index.php?/alaska-hiking-trips/wrangell-st-elias-national-park

redirects to…

https://www.trekalaska.com/?/alaska-hiking-trips/wrangell-st-elias-national-park

       
Wavicujjoys's avatar
Wavicujjoys
1 posts
one year ago
Wavicujjoys's avatar Wavicujjoys

Stripping “index.php?” from URLs To remove “index.php?” from your URLs using .htaccess, you can use the following code:

RewriteEngine On RewriteCond %{REQUEST_URI} ^/index.php\?(.)$ RewriteRule ^index.php\?(.)$ /$1 [R=301,L]

This should redirect any URL containing “index.php?” to the clean version without it. geometry dash meltdown

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.