Special Character problem

New to mod_rewrite? This is a good place to start.

Special Character problem

Postby dark_yahoo » Thu Apr 02, 2009 12:56 pm

Hi Richard!

I do admire your answers and actually I bookmarked this forum as the best reference regarding mod_rewrite.

As of now, my problem is this toy name called "Cute Barbië" and this "Big Ping-pong".

The example generated URL are
1. http://localhost/Products/Big Ping-pong
2. http://localhost/Products/Cute Barbië

My Answer to this is

Options +FollowSymLinks

RewriteEngine On

RewriteRule ^Products/([A-Za-z]+\s?[A-Za-z]+Ã?«?-?[A-Za-z]+)$ index.php?toy=$1

#1 (Big Pong-pong) is working

However, the #2 displays an 404 Not Found Page.

"The requested URL /Products/Cute Barbië was not found on this server."

I know that this stupid letter "ë" triggers the problem. How could I code this in mod_rewrite?

By the way, could you make a tutorial about this RewriteCond and this %{REQUEST_URI} thing? Because I really want to learn this.

Thanks a lot and God Bless!
dark_yahoo
 
Posts: 3
Joined: Thu Apr 02, 2009 10:22 am

Postby richardk » Fri Apr 03, 2009 6:44 am

Try
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteRule ^Products/([^/]+)/?$ /index.php?toy=$1 [QSA,L]


By the way, could you make a tutorial about this RewriteCond and this %{REQUEST_URI} thing? Because I really want to learn this.

REQUEST_URI is a varible, it is part of the URL. If the URL is http://forum.modrewrite.com/posting.php?mode=reply&t=33565, REQUEST_URI is /posting.php.
Other variables: HTTP_HOST = forum.modrewrite.com, QUERY_STRING = mode=reply&t=33565.

RewriteConds are processed after the RewriteRule pattern. The part on the left is checked against the regular expression on the right.
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Diminished question mark

Postby dark_yahoo » Tue Apr 07, 2009 1:13 pm

Thank You for the answer and it indeed helps me a lot!

However, I still have one problem. This is the ?page=$page_id to which it will forcefully convert and show to the browser as Article/$page_id.

This question mark is located in the <a href="?page=$page_id">Blah</a>

Because the site is already working and has a lot of page, I'm planning to rewrite all ?page=page_id in the browser as a clean one and redirect it back.

RewriteRule ^page=([0-9]+)$ /Article/$1 [R]
RewriteRule ^Article/([0-9]+)$ index.php?page=$1 [QSA,L]

How can I solve the "?" problem?

Thank a lot!
dark_yahoo
 
Posts: 3
Joined: Thu Apr 02, 2009 10:22 am

Postby richardk » Wed Apr 08, 2009 1:10 pm

Query strings are matched with the %{QUERY_STRING} variable and RewriteConds.

Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteCond %{QUERY_STRING} ^(.*&)?page=([0-9]+)(&.*)?$ [NC]
RewriteRule ^(index\.php)?$ /Article/%2? [NC,R=301,L]

RewriteRule ^Article/([0-9]+)$ /index.php?page=$1 [QSA,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Complicated String

Postby dark_yahoo » Tue Jun 30, 2009 2:27 pm

I've learned a lot by using your forum. As a proof, below are the codes that I am using now.

From: http://localhost/index.php?topic=1

To : http://localhost/Topic/The-Great-Forum

Solution : RewriteRule ^Topic/([^/]+)/?$ /index.php?topic=$1 [QSA,L]


I successfully did this using PHP and the .htaccess tutorial of this forum.

However, I've encountered some strings that my rewrite solution is not working.

Example : http://localhost/Topic/The-"Great"-Mr.Richard-says-"Yes/No!"-period.

The above samples results some of my problems :
1. When using " (double quotations), the .modrewrite seems not working.
2. When a dot is in the statement or even in the last part, rewrite rule is not working.
3. Some statements like Yes/No has a slash on it. And again modrewrite is not working.

My only solution is this : RewriteRule ^Topic/([^/]+)/?$ /index.php?topic=$1 [QSA,L]

How can I do it? Thanks a lot.
dark_yahoo
 
Posts: 3
Joined: Thu Apr 02, 2009 10:22 am

Postby richardk » Tue Jun 30, 2009 3:25 pm

"[^/]+" means one or more of anything that is not a /. Try replacing it with ".+".
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 104 guests

cron