Forum Moderators: phranque

Message Too Old, No Replies

Problem with mod rewrite from /index.php?id=kac to /kac

         

holee

10:31 am on May 10, 2008 (gmt 0)

10+ Year Member



Hello everyone;

First i would like to tell You that I am not well in English, but i will try. And of course i want to say hello because this is my first post here.

I've got a big problem with my .htaccess file, i'am trying to solve my problem for about two weeks and nothing i can do.

I take my web in the new server where is working Apache 2.2, my .htaccess stop working.

I' ve got URL's like this:
http://www.example.net/index.php?id=kac
http://www.example.net/index.php?id=kac_swome
http://www.example.net/wina/index.php?id=kac_swome

but i want to have like this:

http://www.example.net/kac
http://www.example.net/kac,swome
http://www.example.net/wina/kac,swome

etc.

I've tried to solve with this RewriteRule:

RewriteRule ^(.*)$ index.php?id=$1 [L]

but it isn't working.

I have read on this forum about this:

RewriteRule ^([^./]+)\.html$ /index.php?id=$1 [L]

and it is working on my server, but i don't want ".html" in the end. So i tried to remove this like that:

RewriteRule ^([^./]+)\$ /index.php?id=$1 [L]

and nothing works corectly.

Look at my page:

http://www.example.net/index.php?id=kac

works fine, but:

http://www.example.net/kac

is not ;/

My whole .htaccess file is:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?id=$1 [L]

Please, help me. I dont't have ane ideas to do this myself and my site doesn't work since two weeks ;/
I hope that someone can understand m English ;)

I was looking in that forum an answer but i didn't find, if an identyical problem was somewhwre solved i would be greatful for link.

Bye

[edited by: jatar_k at 1:41 pm (utc) on May 10, 2008]
[edit reason] please use example.net [/edit]

jdMorgan

2:18 pm on May 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi holee, and welcome to WebmasterWorld!

If your new server is Apache 2.2, and your old server was Apache 1.x, then it is possible that you need to add


AcceptPathInfo Off

at the top of your .htaccess file.

You may also need to add


Options +FollowSymLinks -MultiViews

due to version-independent differences in the server configuration.

Try adding these two directives. If this does not help, please try to give us more information on *how* your rules do not work. Do you get an error message in the browser? Do you get any error information in the server error log?

Jim

holee

3:41 pm on May 10, 2008 (gmt 0)

10+ Year Member



jdMorgan, thanks for your quick reply.

And You have right, it works perfectly in URL like (with one word):
http://www.example.net/kac

but when I want to click something like that (two or more words) (#1):
http://www.example.net/kac,regionalny

i get error:

Warning: include(kac,regionalny.php) [function.include]: failed to open stream: No such file or directory in /home/wina/domains/example.net/public_html/index.php on line 113

Warning: include() [function.include]: Failed opening 'kac,regionalny.php' for inclusion (include_path='.:/usr/local/php5/lib/php') in /home/wina/domains/example.net/public_html/index.php on line 113
----------------------------------------------

My .htaccess file:

AcceptPathInfo Off
Options +FollowSymLinks -MultiViews
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?id=$1 [L]

#1
RewriteRule ^(.*),(.*)$ index.php?id=$1_$2 [L]

#2
RewriteRule ^spis,win/(.*)$ index.php?id=spis_win/$1 [L]

#3
RewriteRule ^wino/(.*)$ wino/index.php?id=$1 [L]

-------------------------------------------------
I've got also another problems with mod_rewrite.

#2
http://example.net/index.php?id=spis_wina/a

works, but that:

http://example.net/spis,win/a

doesn't, i've got the same error.
-------------------------------------------------
#3
http://example.net/wino/index.php?id=ciociosan

works, but that:

http://example.net/wino/ciociosan

doesn't.

I have tried to change myself your RewriteRule but I always get the same errors. The older Apach was easier ;)

Sorry, that I have w lot of questions but when i write to server admins they told me "get lost" and do it yourself ;/

One more thanks.

jdMorgan

6:05 pm on May 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The comma "," character is a reserved character in URI-naming. I suggest that you use one of the unreserved characters instead of a comma in your on-page links: - _ . ! ~ * '( )

An alternative would be to encode the comma as %2C

Example: <a href="http://www.example.net/kac%2Cswome">

See RFC 2396 - Uniform Resource Identifiers (URI): Generic Syntax [faqs.org] for more information.

Jim

holee

9:20 pm on May 10, 2008 (gmt 0)

10+ Year Member



But if i added RewriteRulke like this:

RewriteRule ^(.*)-(.*)$ index.php?id=$1_$2 [L]

i got an error:

Internal Server Error

on my entire page.

I don't know if I understand You. In HTML code instead of comma I should give "%2C" ? What about in htaccess code, can I use comma or %2C ?

I tried in every possible way with that and it isn't still working. ;/

http://www.example.net/kac,regionalny

either

http://www.example.net/kac-regionalny

Nothing.

I would prefer comma "," character beacuse i linked my subpages for a long time and it would be big waste for me.

Could You tell how about point #3 form my previous post ?
Why it's not working ?

Thanks a lot that you find a time to response me. I really apriciate.

jdMorgan

10:20 pm on May 10, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Simply put, RFC 2396 says you should not use a comma -- It must be and will be encoded, which may cause you trouble writing mod_rewrite rules, and may also cause problems with script processing.

You must include:


RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

before every new RewriteRule.

Or you may wish to add one instance of:


RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [S=9]

at the beginning of your rules, where "9" is an example of the number of rules to skip if the requested URL exists as a file or directory.

Put your rules in order, from most-specific to least-specific. Use very-specific patterns to avoid unintended pattern matches.

I would suggest:


AcceptPathInfo Off
Options +FollowSymLinks -MultiViews
RewriteEngine on
#
# Skip next 4 rules if URL resolves to existing file or directory
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [S=4]
#
RewriteRule ^spis,win/([^/,]+)$ index.php?id=spis_win/$1 [L]
RewriteRule ^wino/([^/,]+)$ wino/index.php?id=$1 [L]
RewriteRule ^([^/,]+),([^/,]+)$ index.php?id=$1_$2 [L]
RewriteRule ^(.*)$ index.php?id=$1 [L]

Please limit your posts to one question: Language problems will make things too difficult otherwise. I don't speak your language at all, and though you seem to be very good with English, technical language translation is much more difficult that conversational language translation.

Also, it is far easier to get one rule working, then add one more, get that working, then add one more, rather than trying to debug a huge pile of rules all at one time.

Jim

holee

3:03 pm on May 11, 2008 (gmt 0)

10+ Year Member



Jim, one huge thanks to You. Huge Huge thanks.

Everthing works fine and I'm a little wiser than I was before.
I already know where I should ask for help if I will have any technical problems.

Bye