Forum Moderators: phranque

Message Too Old, No Replies

Removing index.php

         

b8caster

3:06 am on Oct 15, 2010 (gmt 0)

10+ Year Member



How do I change /directory/index.php?somestring=value to /directory/?somestring=value across my entire site (including multiple directories)?

I know this has to be simple in htaccess, but for some reason the syntax escapes me.

Running Apache 2.2

Thanks!

jdMorgan

11:50 pm on Oct 15, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this search [google.com] for many prior threads on the subject.

Please post specific questions or problems back here.

Jim

b8caster

10:12 pm on Oct 16, 2010 (gmt 0)

10+ Year Member




Thanks for the link. I tried about 8 or 9 iterations of the rewrite code to no avail. It seems EVERY one of those posts were somebody wanting to change mysite.com/index.php to mysite.com/

That's NOT what I'm asking here. Instead, this is what I'm looking for:

I want all requests to mysite.com/some-directory/index.php?somestring=value redirected to mysite.com/some-directory/?somestring=value where "some-directory" is all the directories on mysite.com.

I simply need to the correct syntax for the rewrite rule, but it appears to be something nobody knows how to do. I was hoping you folks knew, but I'm losing faith.

g1smd

10:18 pm on Oct 16, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Without seeing what code you tried, it is impossible to fix the (probably minor) issue that stopped it from working. Please post your code.

jdMorgan

12:47 am on Oct 17, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I understood your question perfectly, because it is a trivial bit of code.

The following is almost a direct copy-and-paste from the end of the very first thread listed in the search results at the search link I posted above. That code probably would have worked fine for you, but I took the liberty of improving it slightly, with no change to function:

RewriteCond %{THE_REQUEST} ^[A-Z]+\ /([^/]+/)*index\.php([?#][^\ ]*)?\ HTTP/
RewriteRule ^(([^/]+/)*)index\.php$ http://www.example.com/$1 [R=301,L]

Because no query string is specified in the rewriterule, the original query string(s) --if any-- will be passed through unchanged.

If this is not what you want, then the problem is an insufficient requirements specification -- Specifically, for those URLs+querystrings that you wish to redirect, what part or parts of your "somestring=somevalue" query are fixed, and what part or parts can change? If parts can change, what are the possible valid characters, string lengths, etc.?

To describe such things, use statements like "The query string is always a single name/value pair, with the name always being exactly "somestring" and the value being 1 or more lowercase alphanumeric characters including non-contiguous hyphens allowed in any but the first or final position."

That kind of specification makes it easy to get a correct answer fast, since the "value" subpattern is fully described and the query string pattern can be directly coded as: "^somestring=([a-z0-9](-?[a-z0-9]+)*)$"

Jim