Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Htaccess problem


11:15 am on Nov 29, 2012 (gmt 0)


I want a help, if someone can help me, i appreciate..

I download a sourcecode and try to config a website in my localhost... It works, but with a little problem...

When i access:

It doesn't work.

When I access:
It works normaly.

string1.php is a file. I want it appears without .php

My htaccess is like this:

RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} ^.*\.(php)$
RewriteRule ^([^/]+)\/([^/]+)?[\/]?([^/]+)?[\/]?([^/]+)?[\/]?([^/]+)?[\/]?$ $1?q1=$2&q2=$3&q3=$4&q4=$5 [QSA]
2:28 pm on Nov 29, 2012 (gmt 0)

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

Why is (php) in brackets? Not needed.

Why are slashes escaped and in character groups?
simplifies to /?

in your pattern should be replaced by
or similar. Never use .* at the beginning or in the middle of a pattern.

Your "four optional somethings" makes the pattern very ambiguous.

You should either have four separate rules, with 2, 3, 4 and 5 groups, OR use
(use $1, $2, $4) or
(use $1, $2) to capture multiple folder groups all at once in $2 (and $4 in first code snippet) and then explode and count them within the PHP script. Map $1 to the internal php file.

Every rule needs the

Allowing optional slash on the end of the URL means that two different URLs can deliver the same content. You should pick one (without slash) to deliver content, and redirect requests for the other (with slash) using a separate preceding rule.

I am not exactly sure what
RewriteCond %{REQUEST_FILENAME} ^.*\.(php)$

is for. I expect you meant:
RewriteCond $1\.php -f

to test that the first part of the requested URL matches to a real php file.
To map the incoming URL request to a real physical PHP file, look at the rule target and replace

Putting it all together gives:
RewriteCond %{REQUEST_URI} !-d
RewriteCond $1\.php -f
RewriteRule ^([^/]+)/(([^/]+/)*[^/.]+)$ /$1.php?multi=$2 [QSA,L]

or you could use four separate rules, with 2, 3, 4, and 5 groupings.

You'll also need a rule redirecting requests "with slash" to "without slash" as well as the standard non-www/www canonicalisation redirect before any of the rewrites.

Use example.com in all code examples in this forum. It stops the auto-linking function from activating.