.htaccess subfolder not working - .htaccess

I've looked everywhere to try and solve this and I can't get any of the solutions elsewhere to work.
I have a drupal website running on a domain
I have build a new website in www.domain.com/subfolder
In a .htaccess file in the sub folder:
RewriteEngine On
RewriteRule ^/?login$ /index.php?get_action=login [L]
However when I try and visit www.domain.com/subfolder/login I get redirected to the www.domain.com.
I need www.domain.com/subfolder/login to redirect to www.domain.com/subfolder/index.php?get_action=login
How do I accomplish this.
Please help.

I would make use of drupal and instead of using the .htaccess file , I would install Drupal's Login destination module . You can find it here -> http://drupal.org/project/login_destination . I hope it helps .

If your htaccess file is in the subfolder, you can try adding a rewrite base and remove the leading slashes:
RewriteEngine On
RewriteBase /subfolder/
RewriteRule ^login$ index.php?get_action=login [L]
Or, you can explicitly make the target an absolute URL:
RewriteEngine On
RewriteRule ^/?login$ /subfolder/index.php?get_action=login [L]

Related

RewriteRule syntax in .htaccess won't work

I have a simple .htaccess:
RewriteEngine on
RewriteRule ^/locations/$ location.php
The folder "mydomain.com/locations/" does not exist but the locations.php does.
According to the hoster the module mode_rewrite is enabled on the server by default but still my rewrite rule won't work.
The request "mydomain.com/locations/" answers with 404.
What am I doing wrong?
Thanks in advance for the help :)
RewriteRule uses a relative path starting without a leading slash on htaccess context . So remove the slash
RewriteEngine on
RewriteRule ^locations/$ location.php

My htaccess not working in my website but working in testing site

Finally, I managed to write htaccess code and tested it in http://htaccess.madewithlove.be/ and found its correct.
The way the URL is rewritten in this http://htaccess.madewithlove.be/ is working
but when I use the same htaccess code in my website is not working.
new URL http://192.168.1.190/qjyii2/yii2dev3/frontend/web/login.php
Actual URL http://192.168.1.190/qjyii2/yii2dev3/frontend/web/index.php?r=site/login
Htaccess code
RewriteEngine On
RewriteRule ^qjyii2/yii2dev3/frontend/web/([^/]*)\.php$ /qjyii2/yii2dev3/frontend/web/index.php?r=site/$1 [L]
My mod_rewrite is working fine in server. I did put this htaccess under /www/qjyii2/yii2dev3/ and its not working. Any help is highly appreciated.
If you're placing this in /www/qjyii2/yii2dev3/.htaccess then use this code:
RewriteEngine On
RewriteBase /www/qjyii2/yii2dev3/
RewriteRule ^(frontend/web)/([^/]*)\.php$ $1/index.php?r=site/$2 [L,NC,QSA]
.htaccess is per directory directive and Apache strips the current directory path from RewriteRule URI pattern.

Redirecting url using .htaccess in a subdirectory

I have a sub directory named "blog". I want to clean the url when accessing this directory in web browser. So I want that when I type
www.example.com/blog/index.php?id=1
The webbroswer must show like this:
www.example.com/blog/posts/1
I successfully implemented this when there was no sub directory, but in sub directory case it shows me a 404 error.
Here what I have done in my .htaccess file to make it work when I was implementing it in the root directory(not in the subdirectory).
RewriteEngine On
RewriteRule ^posts/([^/]*)$ /index.php?id=$1 [L]
And I wrote my url in the index.php file as
echo '' . $row['title'] . '';
But the problem is when the same thing I tried to implement in a sub directory named "blog", it shows me a 404 error.
I tried this rule in .htaccess., but it did not work.
RewriteCond %{REQUEST_URI} !^/blog/.*$
RewriteRule ^(.*)$ /blog/$1 [L]
I am keeping my .htaccess file in the sub directory named blog.
I tried many questions in StackOverflow, but none seems to solve my problem.
Any help would be appreciated.
Add a rewwrite base to the rules that you had:
RewriteEngine On
RewriteBase /blog/
RewriteRule ^posts/([^/]*)$ index.php?id=$1 [L]
These would be in the htaccess file in the directory /blog/
And make sure in your index.php, you are generating links like:
echo '' . $row['title'] . '';

.htaccess redirects : posting the subsequent uri

I have a website set up where I store all my user profiles in /member-centre/member-directory/USERNAME
My problem is that a number of referrals are posting to a depreciated structure of /members/USERNAME
Is there a way I can configure my .htaccess file to automatically post the requested USERNAME to the correct location? All i've found on google is static redirection.
If this is not possible through .htaccess, is there another method I could use?
Many thanks in advance
If you are looking for a redirect solution, Jon Lin's will work fine. If you want to do a rewrite then put the following in your .htaccess file in the root of your domain
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} ^/members/([^/]+)$ [NC]
RewriteRule . member-centre/member-directory/%1 [L]
if member/centre etc is relative to the root filesystem and not your domain then replace the last line with (just leading slash)
RewriteRule . /member-centre/member-directory/%1 [L]
Do you mean something like:
RedirectMatch 301 ^/members/([^/]+)/? /member-centre/member-directory/$1
This redirects the browser with a permanent redirect.
Try something like this:
RewriteRule ^members/ /member-centre/member-directory/ [L]

.htaccess redirect for images from old folder to new folder

I have just moved from Drupal + Wordpress to a site completely built in WordPress.
Duly I have a set of images where the files no longer exist and need to try and keep all the images in the one folder (if possible). Duly I need to send requests for any gif|png|jpg that are for http://www.domain.com/blog/wp-content/uploads/ to http://www.domain.com/wp-content/uploads.
If anyone could help would be appreciated - my .htaccess aint what it once was. Thanks in advance
If you google for "htaccess redirect", the top link is this:
http://www.htaccessredirect.net/
If you use the "301 Redirect Directory" section, you get this code:
//301 Redirect Entire Directory
RedirectMatch 301 /blog/wp-content/uploads/(.*) /wp-content/uploads/$1
As far as I know the target domain should be absolute, so the following might work:
//301 Redirect Entire Directory
RedirectMatch 301 /blog/wp-content/uploads/(.*) http://www.domain.com/wp-content/uploads/$1
Please try this rule in your .htaccess:
RewriteEngine On
RewriteRule ^/blog/wp-content/uploads/(.+)\.(png|gif|jpg)$ wp-content/uploads/$1.$2 [QSA,L]
Try this
RewriteEngine on
RewriteCond %{HTTP_REFERER} ^http://www.domain.com/blog/wp-content/uploads [NC]
RewriteRule .* http://www.domain.com/wp-content/uploads [NC,L]
You could try and put this
RewriteEngine ON
RewriteRule ^/blog/wp-content/(.*)$ http://newdomain.com/wp-content/$1 [R=301,L]
What I have hated about all the re-write rules and redirect options for .htaccess files is they all rely on hardcoding the path (URI) and/or server for the redirect.
The point of the ".htaccess" files it it should be for the current directory! It could be referenced in a number of different ways, installed on different servers in different locations. So trying it down to a specific location for a simple directory rename is illogical.
The solution is to somehow incorporate the current URI (regardless or where the ".htaccess" location) into the result...
This is my current solution for location independent ".htaccess" redirect for a renamed sub-directory, and even I admit it is not perfect... BUT IT WORKS...
Options +FollowSymLinks
RewriteEngine On
RewriteRule ^OLDdir/.*$ %{REQUEST_URI}::: [C]
RewriteRule ^(.*)/OLDdir/(.*)::: $1/NEWdir/$2 [R,L]

Resources