homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

Htaccess problem

Msg#: 4523539 posted 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]



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

Msg#: 4523539 posted 2:28 pm on Nov 29, 2012 (gmt 0)

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
[L] flag.

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
$1?q1=... with /$1.php?q1=...

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.

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved