views:

1183

answers:

7

We have a website made by Django. And there is no problem when access following url on local working environment:

http://site/tags/c%23/

"c%23" is urlencode of "c#", that works fine locally. But after we deploy it on Bluehost hosting server (apache+fastcgi), this URL has been resolved to a new address like this:

http://site/t/tags/c/

That's too weird. Probably it's not a Django's problem, but have something to do with Apache url's rewrite. If you have any idea or suggestion how to fix this please let me know. Thanks in advance.

Here is the .htaccess file may be considered:

AddHandler fcgid-script .fcgi 
#AddHandler fastcgi-script .fcgi 
#AddHandler application/cgi .fcgi 
#AddHandler cgi-script .fcgi 
RewriteEngine On 
RewriteBase / 
#static file setting 
RewriteRule ^(media/.*)$ - [L] 
RewriteRule ^(static/.*)$ - [L] 
RewriteCond %{REQUEST_URI} !(dispatch.fcgi) 
RewriteRule ^(.*)$ dispatch.fcgi/$1 [L]

and the dispatch.fcgi file:

#!/home/***/python/bin/python 
import sys, os 
# Add a custom Python path. 
sys.path.insert(0, "/home/***/python") 
sys.path.insert(0, "/home/***/working/Django-1.0") 
os.chdir("/home/***/working/Django-1.0/project") 
os.environ['DJANGO_SETTINGS_MODULE'] = "project.settings" 
from django.core.servers.fastcgi import runfastcgi 
runfastcgi(["method=threaded", "daemonize=false"])

UPDAET: If this is caused by settings in httpd.conf, how can I override in .htaccess file while I don't have permission to it?

+4  A: 

Just some tips before going further:

Have you tried with other characters such as a space (%20) or an accented ASCII character? Also, have you tried putting other characters after the %23 (other than the slash) to see if they're stripped also?

One guess could be that as the # is considered as an anchor on the current page, the # and whatever is after will be stripped in the rewrite.

lpfavreau
A: 

@lpfavreau,thanks for your reply.

I tried space(%20) and it is ok - it can show the space in print. When I add more characters after %23, it behaviors like this:

http://domain/tags/c%23         http://domain//tags/c/
http://domain/tags/c%23/        http://domain/t/tags/c/
http://domain/tags/c%23h        http://domain/t/tags/c/
http://domain/tags/c%23he       http://domain/ta/tags/c/
http://domain/tags/c%23hel      http://domain/tag/tags/c/
http://domain/tags/c%23hell     http://domain/tags/tags/c/
http://domain/tags/c%23hello    http://domain/tags//tags/c/
http://domain/tags/c%23hellow   http://domain/
http://domain/tags/c%23hellowo  http://domain/tags/c%23/////////////////////tags/c/

and the last one the page can't display in IE, while Chrome says 'This webpage has a redirect loop.'

I think you are right. There must be some rewrites for "#", but seems I don't have enough access to httpd.conf. How can i overwrite that in .htaccess if that's the right way?

chagel
A: 

I still haven't solved this issue yet.

It seems the current problem is how to add "#" rewrite in .htaccess and overwrite the one probably existed in apache configuration?

Is that possible?

chagel
+1  A: 

I'd have to agree with the first answer - and without access to the apache configuration, you might be out of luck. Using 'CSharp' or something in that vein might be the way to go.

Andy Mikula
+1  A: 

# has special meaning in URI, same as / or ? does. Do you have this issue with other symbols? Ultimately, you shouldn't be using a # sign in a URI anyway, unless you're referring to an anchor on the page.

Alex JL
No problem found so far for other symbols.# is useful sometimes in context like on stackoverflow, we use this url to express "c#" tag:http://stackoverflow.com/questions/tagged/c%23
chagel
A: 

http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html

Read the anchor rewriting section.

if this works for you please tell me how to do in lighttpd.
A: 

hi, im not even able to get this working in my local app. which Field do you use in your model? how is the slug stored in the db and how does your url definition looks like for this content?

thx