How to write .htaccess if django project is in subfolder and subdomain? - django

The path to my django site is: staging.ninjawebsite.com/clients/project/.
I want that to be treated as the base url. The django project is in the public_html/clients/project subfolder. Everything seems to be working fine but all links to say /city/ should go to staging. ninjawebsite.com/clients/project/city/ but it goes to staging.ninjawebsite.com/city/.
Here is my .htaccess file:
AddHandler fcgid-script .fcgi
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^(media/.*)$ - [L]
RewriteRule ^(admin_media/.*)$ - [L]
RewriteCond %{REQUEST_URI}!(django.fcgi)
RewriteRule ^(.*)$ /clients/project/django.fcgi/$1 [QSA,L]
Somebody please help me! Thanks.

Related

Apache .htaccess "Redirect to non-url" error

I've not used URL rewriting on .htaccess for a while, and now I think I've forgot some of the basis.
This is my server directory structure:
https://www.domain.com/dir/
In which I've put my website, with those files:
index.php
list.php
edit.php
home.php
What I wanted to achieve is this: User writes url like https://www.domain.com/list and .htaccess sends that request to index.php?section=list.
So, this is my current .htaccess:
RewriteEngine On
RewriteBase /dir
Redirect on HTTPS
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
RewriteRule /([a-zA-Z]+)/$ /index.php?section=$1 [NC,L]
Testing it on htaccess tester seems to work as expected, but not on my webserver.
I've got no more .htaccess files in the server root dir, and by viewing server logs I only get Redirect to non-URL errors.
I've also seen this answer but it didn't help me so far.
Have this .htaccess in /dir/ directory:
RewriteEngine On
RewriteBase /dir/
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([\w-]+)/?$ index.php?section=$1 [QSA,L]
This will support pretty URL as http://domain.com/dir/list

htaccess, Regex, Rewrite URL

hmm I have a problem with my .htaccess, I wanted to rewrite this:
http://domain.com/a/thread-103518.html#103518
to this
http://domain.com/a/103518
In other words... I want to delete the "thread-" and everything after the "." The /a/ must be variable... there are other forums with /bla/ and /code/
Do you have a clue for me? Thank you
My .htaccess right now:
RewriteCond %{REQUEST_FILENAME} !-d RewriteCond
%{REQUEST_FILENAME}.php -f RewriteRule ^(.*)$ $1.php
RewriteCond %{THE_REQUEST} ^[A-Z]+\ /index.php RewriteRule
^index.php/?(.*) /$1 [L,R=301]
Add this to the .htaccess file in your DOCUMENT_ROOT
RewriteEngine On
RewriteRule ^([^/]+)/thread-(\d+) $1/$2? [DPI,L,R]
Tested in Apache 2.2 and 2.4 :)
This assumes that mod_rewrite is both installed and activated for htaccess files.
If you are not sure, to check if mod_rewrite is installed, look at the list of installed modules in the output of phpinfo();
By default, mod_rewrite is not enabled for htaccess files. If you are managing your own server, open httpd.conf
and make sure that the webroot directory block contains one of these lines: AllowOverride FileInfo or AllowOverride All

htaccess - Redirect with exception

I have a webpage where I'm going to move the old page to a subdirectory, while installing ExpressionEngine on the root. However, I want to redirect users to the subdirectory now. While I'm still able to build the new ExpressionEngine site on the root. Is this possible?
Basically, whenever a user navigates to http://www.mywebsite.com, I want to redirect them to http://www.mywebsite.com/old
But, when I navigate to http://www.mywebsite.com/new, I actually want to redirect it to http://www.mywebsite.com/index.php, because ExpressionEngine is installed on the root.
The idea is that when the page is done, I just have to remove these rules from htaccess and that's that.
As of now I've only got this rule set up:
redirect /index.php http://www.mywebsite.com/old/
This creates a problem because /index.php is the actual ExpressionEngine index.php, which is the default page of the site.
You can use this code in DOCUMENT_ROOT/.htaccess
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/?$ /old [L,R]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.+$ /index.php [L,NC]

.htaccess RewriteRule from download.php?token=something into /download/something

I have this URL:
http://www.example.com/subf/subf2/download.php?token=6309838552568
It is possible to rewrite this url into this url?
http://www.example.com/subf/subf2/download/6309838552568
Note: If someone types a URL like this:
http://www.example.com/subf/subf2/download/6309838552568/sbuf3/subf4
i want to show them an error page.
Answer below
Hint: Include files like JS and CSS need to be refer in absolute paths.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT/subf/subf2/ directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /subf/subf2/
RewriteRule ^(download)/(\w+)/?$ $1.php?token=$2 [L,QSA,NC]
# to take care of css, js, images
RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_URI} \.php$
RewriteRule ^download/(.+)$ /subf/subf2/$1 [L,R=301,NC]

How to create an exception folder in a django site?

There are a few folders where I house my django site that I want to be rendered as it would on any other non-django site. Namely, forum (vbulletin) and cpanel. I currently run the site with fastcgi. My .htaccess looks like this:
AddHandler application/x-httpd-php5 .htm
AddHandler application/x-httpd-php5 .html
AddHandler fastcgi-script .fcgi
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
AddHandler application/x-httpd-php5 .htm
RewriteCond %{REQUEST_URI} !(mysite.fcgi)
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]
What are lines I can add so www.mysite.com/forum can not be picked up by django url and be rendered as it would do normally. Thanks.
in your apache vhost conf :
Alias /forum /home/django/project/forum
But i think its better to put your php stuff not inside your django project
You can do
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !(mysite.fcgi) [OR]
RewriteCond %{REQUEST_URI} ^forum
RewriteRule ^(.*)$ mysite.fcgi/$1 [QSA,L]
This will ensure that the mysite.fcgi rule is triggered only if the url doesn't begin with forum.