Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite with special characters (%)

         

meee

8:25 am on Sep 16, 2010 (gmt 0)

10+ Year Member



I have a site in "exostic" language. For SEO purposes, I have in url special characters. I don't want to change url because than I would lose SEO benefit of having title in url.

Example:
domain/%CF%80%CE%BF%CE%B4%CF%8C%CF%83%CF%86%CE%B1%CE%B9%CF%81%CE%BF
which is actually
domain/article.php?title=%CF%80%CE%BF%CE%B4%CF%8C%CF%83%C F%86%CE%B1%CE%B9%CF%81%CE%BF

I would like to make rewrite_rule ^/?(/anything)$ /article.php?url=$1 [L]

The problem is when inside everything is %.
I tried RewriteRule ^/?(.*)$ /article.php?url=$1 [L] and it doesn't work.

Then I tried
to change url to domain/%CF%80%CE%BF%CE%B4%CF%8C%CF%83%CF%86%CE%B1%CE%B9%CF%81%CE%BF/3423 (number as article id)
and made rule
^/?(.*)/([-a-zA-Z_&0-9&,!]+)$ /article.php?url=$1 [L]

This works. I have no idea why in second case it works and in first not.

I hope anybody can help me!

meee

5:44 pm on Sep 16, 2010 (gmt 0)

10+ Year Member



I found a solution. If anybody else need, this is what I did:
RewriteRule ^/?([^/.]+)$ /article.php?url=$1 [L]

jdMorgan

4:04 pm on Sep 18, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The first rule failed because it will rewrite "article.php" to itself -- creating an infinite loop. Check your server error log file, and you will find warnings about this.

Your second rule works because it excludes requested URL-paths containing slashes or periods from being rewritten, thereby "stopping the loop" after the request is rewritten to "article.php".

However, it has a flaw: You will not be able to use "article names" which contain any periods or slashes, therefore making it impossible to include things like dates, prices, or domain names in article names. For example, the following article name cannot be used, because your new rule won't rewrite it: "eBay.com to price iPad at $150.00 after 09/18/2010!"

A better solution might be to explicitly stop the loop by excluding only the script filename itself:

RewriteCond $1 !^article\.php$
RewriteRule ^(.+)$ /article.php?url=$1 [NE,L]

This code is intended for use in the /example.com/.htaccess file. If your code is located elsewhere, then please say so.

Jim