Forum Moderators: phranque

Message Too Old, No Replies

Can't figure out, how to config my .htaccess for good working.pls help

         

junkas

11:43 pm on Apr 17, 2011 (gmt 0)

10+ Year Member



I'm using scripts, which has redirecting.

Firstly none of pages links didin't work, but when i disable multiviews in my server, some of them works fine (flop.php, top.php etc.), but more difficult URL's (such as members, view, category) NOT. I can't find an error :( Pls. help.

Here is my .htaccess file.


<IfModule mod_rewrite.c>
# Enable mod_rewrite, disable multiviews
# For security reasons, Option followsymlinks cannot be overridden.
#Options -multiviews
Options -multiviews
Options +FollowSymLinks
# Turn on the rewrite engine
# Rewrite URL-paths not ending with a filetype (".") or trailing slash (in any {sub}directory) to <URL-path>.php
RewriteEngine on
RewriteRule ^(([^/]+/)*([^./]+))$ $1.php [L]
RewriteRule ^signup$ /signup.php
RewriteRule ^category/(.*)/(.*) /category.php?cat=$1&name=$2 [L]
RewriteRule ^view/(.*)/(.*) /view.php?cat=$1&name=$2 [L]
RewriteRule ^members/(.*)/(.*) /memberprofile.php?pid=$1&name=$2 [L]
RewriteRule ^top$ /top.php
RewriteRule ^flop$ /flop.php
RewriteRule ^random$ /random.php
RewriteRule ^password$ /password.php
RewriteRule ^confirmemail/(.*) /confirmemail.php?code=$1
RewriteRule ^resetpassword/(.*) /resetpassword.php?code=$1
RewriteRule ^editaccount$ /editaccount.php
RewriteRule ^changeemail$ /changeemail.php
RewriteRule ^changepass$ /changepass.php
RewriteRule ^resendconfirmation/(.*) /resendconfirmation.php?userid=$1
RewriteRule ^favorites$ /favorites.php
RewriteRule ^members/(.*)/(.*) /memberprofile.php?pid=$1&name=$2
RewriteRule ^advanced_search$ /advanced_search.php
RewriteRule ^moderate$ /moderate.php
RewriteRule ^termsofuse$ /termsofuse.php
RewriteRule ^privacypolicy$ /privacypolicy.php
RewriteRule ^aboutus$ /aboutus.php
RewriteRule ^advertising$ /advertising.php
RewriteRule ^contactus$ /contactus.php
RewriteRule ^mailbox$ /mailbox.php
RewriteRule ^log_out$ /log_out.php
RewriteRule ^man$ /man.php
RewriteRule ^woman$ /woman.php
</IfModule>

<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off

# The below probably isn't needed,
# but better safe than sorry.
SecFilterScanPOST Off
</IfModule>

g1smd

11:48 pm on Apr 17, 2011 (gmt 0)

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



Delete the ifModule tags.

Add the [L] flag to every rule.

The very first rule matches many requests preventing a more specific rule further down the list from ever running. Move the first rule further down the list, so that "more specific" rules get to run first.

Change the ambiguous (.*) patterns to something else.

See this thread from 2 days ago for inspiration: [webmasterworld.com...]

junkas

12:10 am on Apr 18, 2011 (gmt 0)

10+ Year Member



"Delete the ifModule tags. "
Could you say,what you talking about?

"<IfModule mod_security.c>
# Turn off mod_security filtering.
SecFilterEngine Off

# The below probably isn't needed,
# but better safe than sorry.
SecFilterScanPOST Off
</IfModule> "

THIS?


And it would be very good,if you could, hot to change this line:
RewriteRule ^view/(.*)/(.*) /view.php?cat=$1&name=$2 [L]

Because, you said, that (.*)/(.*) is not suitable for this.

Thank you very much.

wilderness

1:50 am on Apr 18, 2011 (gmt 0)

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



Remove these four lines entirely.

<IfModule mod_rewrite.c>
</IfModule>
<IfModule mod_security.c>
</IfModule>

g1smd

6:25 am on Apr 18, 2011 (gmt 0)

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



The
/(.*)/(.*)
is better done with
/([^/]+)/(.*)
here.

Add the [L] flag to every rule.

junkas

7:11 am on Apr 18, 2011 (gmt 0)

10+ Year Member



Thanks, but I did everything you said, but my problem still remains.
It is, when i click on story in my script (view) the URL is for example:
[myname.lt...]

I don't know what to do.
Here is my full .htaccess after editing.

<IfModule mod_rewrite.c>
# Enable mod_rewrite, disable multiviews
# For security reasons, Option followsymlinks cannot be overridden.
#Options -multiviews
Options -multiviews FollowSymLinks
# Turn on the rewrite engine
# Rewrite URL-paths not ending with a filetype (".") or trailing slash (in any {sub}directory) to <URL-path>.php
RewriteEngine on
RewriteRule ^(([^/]+/)*([^./]+))$ $1.php [L]
RewriteRule ^signup$ /signup.php [L]
RewriteRule ^category/([^/]+)/(.*) /category.php?cat=$1&name=$2 [L]
RewriteRule ^view/([^/]+)/(.*) /view.php?cat=$1&name=$2 [L]
RewriteRule ^members/([^/]+)/(.*) /memberprofile.php?pid=$1&name=$2 [L]
RewriteRule ^top$ /top.php [L]
RewriteRule ^flop$ /flop.php [L]
RewriteRule ^random$ /random.php [L]
RewriteRule ^password$ /password.php [L]
RewriteRule ^confirmemail/(.*) /confirmemail.php?code=$1 [L]
RewriteRule ^resetpassword/(.*) /resetpassword.php?code=$1 [L]
RewriteRule ^editaccount$ /editaccount.php [L]
RewriteRule ^changeemail$ /changeemail.php [L]
RewriteRule ^changepass$ /changepass.php [L]
RewriteRule ^resendconfirmation/(.*) /resendconfirmation.php?userid=$1 [L]
RewriteRule ^favorites$ /favorites.php [L]
RewriteRule ^members/([^/]+)/(.*) /memberprofile.php?pid=$1&name=$2 [L]
RewriteRule ^advanced_search$ /advanced_search.php [L]
RewriteRule ^moderate$ /moderate.php [L]
RewriteRule ^termsofuse$ /termsofuse.php [L]
RewriteRule ^privacypolicy$ /privacypolicy.php [L]
RewriteRule ^aboutus$ /aboutus.php [L]
RewriteRule ^advertising$ /advertising.php [L]
RewriteRule ^contactus$ /contactus.php [L]
RewriteRule ^mailbox$ /mailbox.php [L]
RewriteRule ^log_out$ /log_out.php [L]
RewriteRule ^man$ /man.php [L]
RewriteRule ^woman$ /woman.php [L]
</IfModule>


This line "RewriteRule ^(([^/]+/)*([^./]+))$ $1.php [L]" I can't moving, because after that all links not working.


Thank you, for your support.

g1smd

7:30 am on Apr 18, 2011 (gmt 0)

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



A request for:

example.com/members/12345/joebloggs


will be matched by

RewriteRule ^(([^/]+/)*([^./]+))$ $1.php [L]


and rewritten to the internal server filepath at:

members/12345/.php


This rule will never match:

RewriteRule ^members/([^/]+)/(.*) /memberprofile.php?pid=$1&name=$2 [L]


This occurs because you have the rules in the wrong order. The more general rule must be listed last.

Additionally, remove the two <ifModule> tags as directed.

junkas

7:47 am on Apr 18, 2011 (gmt 0)

10+ Year Member



Sorry, i'm totaly green in .htaccess editing. Maybe you could show me how my file should be look like?
Because it's so difficult to my to understand. Maybe because and my english is not very good. :/

wilderness

2:18 pm on Apr 18, 2011 (gmt 0)

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



theoretically speaking you may as well change to the following:

RewriteEngine on
RewriteRule ^(([^/]+/)*([^./]+))$ $1.php [L]

removing all the others.

Because this line takes precedence over all the others, as g1smd has explained twice.


or, you may move that line further down the order, until you find the location that fits your requirements.
EX (<snip lines.>):

RewriteEngine on
RewriteRule ^signup$ /signup.php [L]
RewriteRule ^category/([^/]+)/(.*) /category.php?cat=$1&name=$2 [L]
RewriteRule ^view/([^/]+)/(.*) /view.php?cat=$1&name=$2 [L]
RewriteRule ^members/([^/]+)/(.*) /memberprofile.php?pid=$1&name=$2 [L]
RewriteRule ^top$ /top.php [L]
RewriteRule ^flop$ /flop.php [L]
RewriteRule ^(([^/]+/)*([^./]+))$ $1.php [L]

junkas

6:10 pm on Apr 18, 2011 (gmt 0)

10+ Year Member



thanks for fast reply , but i've tried both solutions.

And both of them didin't help.

Website open links 4example :
RewriteRule ^top$ /top.php [L]
RewriteRule ^flop$ /flop.php [L], but

when I try to open one of this:
RewriteRule ^category/([^/]+)/(.*) /category.php?cat=$1&name=$2 [L]
RewriteRule ^view/([^/]+)/(.*) /view.php?cat=$1&name=$2 [L]
RewriteRule ^members/([^/]+)/(.*) /memberprofile.php?pid=$1&name=$2 [L]

I just get 404 error :(

wilderness

6:20 pm on Apr 18, 2011 (gmt 0)

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



I just get 404 error


Your going to need to move the error lines,

one at a time

below the "previously supplied bolded line",

1) Then upload the modifed htaccess
2) clear your browser cache
3) reload the page.
4) You'll be required to repeat steps 1 through 3 after "moving" each line, and until you provide the correct functioning order (nobody is able to supply this correct order to you, as nobody has access to your server).

For a hint on 404's, you should review your "error logs", to determine cause. Or HTTP Headers utilizing a plug-in.

g1smd

9:15 pm on Apr 18, 2011 (gmt 0)

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



You can also simplify some of the rules by using local OR syntax:

RewriteRule ^(signup|(t|fl)op|random|password|editaccount|change(email|pass)|favorites|advanced_search|modera
te|termsofuse|privacypolicy|advertising|(about|contact)us|mailbox|log_out|(wo)?man)$ /$1.php [L]
RewriteRule ^(confirmemail|resetpassword)/(.*) /$1.php?code=$2 [L]
RewriteRule ^(view|category)/([^/]+)/(.*) /$1.php?cat=$2&name=$3 [L]
RewriteRule ^resendconfirmation/(.*) /resendconfirmation.php?userid=$1 [L]
RewriteRule ^members/([^/]+)/(.*) /memberprofile.php?pid=$1&name=$2 [L]
RewriteRule ^(([^/]+/)*([^./]+))$ /$1.php [L]

junkas

10:10 pm on Apr 18, 2011 (gmt 0)

10+ Year Member



Thank you guys for support, but I've tried everything you suggest. :/
I don't know, if line "RewriteRule ^(([^/]+/)*([^./]+))$ $1.php [L]" is not on the TOP, links not working. If I put line on the top, "simple" links working.
Every line moving "disabling" links working.

Maybe there is a problem not in .htaccess? But if it would be not in this file, why some links works well, some not.
I'm using FMyscript from www.fmyscript.com.

g1smd

7:15 am on Apr 19, 2011 (gmt 0)

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



Options -multiviews
Options +FollowSymLinks


should be

Options -MultiViews +FollowSymLinks

junkas

10:39 pm on Apr 21, 2011 (gmt 0)

10+ Year Member



big thank you guys for your help. everything works great after I edit .htaccess to:

RewriteEngine On
RewriteRule ^(signup|(edit)?account|log(_?out|in)|(t|fl)op|random|password|change(email|pass)|favorites|adv(anced_search|ertising)|moderate|termsofuse|privacypolicy|aboutus|contactus|mailbox|(wo)?man) $1.php [L]
RewriteRule ^view/([^/]+)/([^/]+)$ view.php?cat=$1&pid=$2
RewriteRule ^category/([^/]+)/(.*)$ category.php?cat=$1&name=$2 [L]
RewriteRule ^resendconfirmation/(.*)$ resendconfirmation.php?userid=$1 [L]
RewriteRule ^members/([^/]+)/(.*)$ memberprofile.php?pid=$1&name=$2 [L]

g1smd

11:18 pm on Apr 21, 2011 (gmt 0)

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



I see that
confirmemail
and
resetpassword
have disappeared from the list.

You have gained a
login
and
logout
as well as an
account
.

The parameters associated with
view
have also changed.

You need the
[L]
flag on EVERY rule.