my web host seems to have some kind of alias folder on my domain called defaultsite. This isnt a folder inside my ftp, so I would like to edit the htaccess on the root to make any access to defaultsite url redirect to the root of the website or at least rewrite the root content.
any ideas how i can do this?
thanks
Assuming the "defaultsite" folder doesn't have an htaccess file, you just need this near above your other rewrite rules.
RewriteEngine On
RewriteRule ^defaultsite/ / [L,R]
Related
I want to internally redirect requests from /media/myspecialdir/image.jpg to /myspecialdir/image.jpg
If it was just an .htaccess file in the document root, this would be straight forward. The problem is that the /media directory already exists and contains contains an .htaccess file. This means that requests to /media/myspecialdir/image.jpg are intercepted by that .htaccess file.
Is it possible to redirect from a subdirectory of the document root to another subdirectory of the document root.
I've tried stuff like:
RewriteRule (.*) ../myspecialdir/$1 [L]
but this still prefixes a media dir to the rewritten URL.
With your shown samples, could you please try following. Considering that your htaccess file is present inside media folder. Please clear your browser cache before testing your URLs.
RewriteEngine ON
RewriteBase /media/
##Then your rules from here.........
Is it possible to redirect from a subdirectory of the document root to another subdirectory of the document root.
Yes that is definitely possible. Have this rule inside /media/.htaccess:
RewriteEngine On
RewriteRule .+ /myspecialdir/$1 [L]
This assumes that myspecialdir exists right under site root. Since you specifically asked for internal rewrite, this will keep URL as: /media/myspecialdir/image.jpg but will load content from /myspecialdir/image.jpg.
i'm working on a drupal7 multisite setup based on subdirectories where example.com is used for the main website and example.com/subsite is another standalone drupal install. subsite is a symlink located in the root directory and also pointing to the root directory to give the subsite access to drupal core files.
now i have to make static content available via example.com/subsite/static, so i created a directory static in the root directory. that all works fine.
the problem is, that example.com/static is now also accessable and i want to prevent that.
i tried to redirect all requests to /static to /subsite/static resulting in inconsistent behaviour and redirect loops.
directory structure:
/
/{various drupal directories}
/subsite -> /
/static
rewrite rule:
RewriteRule ^/static/(.*)$ /subsite/static/$1 [R,L]
thx in advance
Is this what you want?
RewriteBase /
RewriteRule ^static/(.*)$ /subsite/static/$1 [L,R=301]
RewriteRule ^subsite/static/(.*)$ /static/$1 [L]
In the first line we redirect all call to /static/ to /subsite/static/.
In the second line we rewrite all call to /subsite/static/ to /static.
If it doesn't work please post your whole .htaccess file.
i fixed the redirect loops by using a rewrite condition, should have thought of that before.
RewriteCond %{REQUEST_URI} !^/subsite/(.*)$
RewriteRule ^static/(.*)$ /subsite/static/$1 [L,R=301]
thx anyway #florian-lemaitre for trying to help me
I have a shared host. Default url, www.mywebsite.com, on that host points to public_html directory. I have build a new directory, wordpress, under public_html. And i want to redirect my users to the wordpress directory. But i don't want to show /wordpress/ pathname on address bar.
What i have tried until now with .htacces puts the /wordpress/ pathname on address bar like www.mywebsite.com/wordpress/. However i want to show www.mywebsite.com even if it was redirected to the wordpress subdirectory.
In general you just point it using .htaccess but I think there are other considerations as well. There is already an article from wordpress on how to do this as this is a very common thing. That is the best place to start is on wordpress' site.
In the htaccess of the root, you should be able to do a simple rule like this.
RewriteEngine On
RewriteRule ^/?$ /wordpress [L]
https://codex.wordpress.org/Giving_WordPress_Its_Own_Directory
We took over a website with about a kabillion pages in the old site root directory done in htm that need to be retired. I want to do a 301 redirect from the pages to the index.php in the root directory of the new site using a wildcard. An example of the page naming structure follows:
oldpage_dees.htm
oldPage_dat.htm
oldPage_deeudderting.htm
and so on. As stated, I need them redirected to the index.php in the root directory. Going by examples and discussions here I've tried:
RewriteEngine On
RewriteRule ^/oldpage_([\w]*).htm$ /index.php [R=301,L]
but I get a 404 error.
Any suggestions? Thanks in advance!
As .htaccess is directory level configuration file, you don't need to specify forward slash, I think this will do the job:
RewriteEngine On
RewriteRule ^oldpage_([\w]*).htm$ index.php [R=301,L]
Meanwhile, you can use the following .htaccess tester to debug your rewrite rules.
I have the following problem - my site is located one folder below the /www folder on my hosting account, let's say its /www/shop. All the visitors that come to the main domain are then redirected by .htaccess file in the /www folder which takes them to the subfolder.
Should I make this redirect 301 Permanent, so that search engines could index my site better?
Here's the simple .htaccess that I use for the purpose:
RewriteEngine On
RewriteRule ^$ /shop [L]
As long as it's really permanent, yes.