is htaccess is need to placed in every sub folder - .htaccess

i am using the .htaccess for the first time and as every where shows i tried the following code to get the clean url
RewriteEngine on
RewriteRule ^address/([0-9a-zA-Z]+)$ detail.php?add=$1
i also tried to modify it to
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^address/([0-9a-zA-Z]+)$ detail.php?add=$1
But it is not working. is it because i have placed in the main directory and the detail.php is in a folder "content"?

Related

.htaccess: Rewriting Query Not Working

I am trying to change the URL from:
/chat/create?ref=9dsda to /chat/create/refer/9dsda
However, everytime I go to the lather, I get the error:
Not Found: The requested URL /chat/create/ref/9dsda was not found on this server.
This is my .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^/create/refer/([^/]+) /create?ref=$1
I've tried several things such as adding RewriteBase /chat/ without success.
If your htaccess is in the root ,try :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^chat/create/refer/([^/]+)/?$ /chat/create?ref=$1 [L]
If it is inside the /chat dir ,try :
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^create/refer/([^/]+)/?$ /chat/create?ref=$1 [L]
htaccess is a per-directory context so you don't need to match against the folder that the htaccess is in.

.htaccess rewrite #username and #username/photos

hi guys i am trying to rewrite a url but getting errors
i would like to rewrite
www.example.com/photos.php?u=username
to
www.example.com/#username/photos
here is my code
IndexIgnore *
RewriteEngine On
Options +FollowSymLinks
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^#([A-Za-z0-9]+)$ user.php?u=$1 [NC,L]
RewriteRule ^#([A-Za-z0-9]+)$/^([A-Za-z0-9]+)$ user.php?u=$1 photos.php?u=$1 [NC,L]
Your first RewriteRule looks fine, but your second RewriteRule is full of errors.
You're trying to feed the right hand of the rule with 2 different address as seen at:
user.php?u=$1 photos.php?u=$1
Your rule on the left hand have a terminator sign at the middle of the regex and after it you start a new regex which would not work as well:
^#([A-Za-z0-9]+)$/^([A-Za-z0-9]+)$
This should work for your needs and it should be placed inside your .htaccess file, which should be located inside your domain ROOT folder along with both the photos.php and the user.php files or it will not work.
IndexIgnore *
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^#([a-zA-Z0-9]+)/photos$ photos.php?u=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^#([a-zA-Z0-9]+)$ user.php?u=$1 [QSA,L]
If you have a different folder setup then update your question with more information on it so I can update the rule to fit it.
The above rules will allow you to access the photo page in the following format:
www.example.com/#username/photos
And the users page in the following format:
www.example.com/#username

Using htaccess to remove sub-directories from URL in CodeIgniter

My CodeIgniter project is placed inside sub-folders and I want to hide those two sub-folders with .htaccess.
Everything is working fine but my current URL looks like this:
example.com/folder1/folder2/ci_project/class/function/$id
I want this to be:
example.com/class/function/$id
Now, I am using this simple .htaccess code in order to remove the index.php from URL:
Options +FollowSymLinks
RewriteEngine on
# Send request via index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Any Ideas?
when i use the following code in htaccess file inside folder1/folder2/ci_project, it does hide the sub directories but i get the error "Object not found"
RewriteCond %{REQUEST_URI} !^/folder1/folder2/ci_project/
RewriteRule ^(.*)$ /folder1/folder2/ci_project/index.php/$1 [L]
Move your current .htaccess file from your ci_project/ to the root of domain, and replace these code inside it:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond $1 !^(robots\.txt|favicon\.ico|public)
RewriteRule ^(.*)$ /folder1/folder2/ci_project/index.php/$1 [L]
</IfModule>
In this case, you should place your public files in a folder like public at the root of the domain.
You should add other folders (like public) to RewriteCond if you don’t want them to be treated by RewriteRule.
If multiple application are exist in the same domain, you might want to consider this option:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /folder1/folder2/ci_project/index.php/$1 [L]
</IfModule>

How do i redirect a non-existent folder to similar folder?

I am creating a website where I want the members profile links as follows:
somedomain.com/someuser1/ -> somedomain.com/#!/home/someuser1/
somedomain.com/someuser2/ -> somedomain.com/#!/home/someuser2/
etc...
because i don't want to fill the root folder up with a bunch of member profile folders. Can this be done easily in the .htaccess file with rewrites?
I believe i would need to pull the 'someuser1' and 'someuser2' values and append them during the rewrite, but i'm not sure how to do that... the member folders will exist in the /home/ folder, but not the root folder...
Thanks!
Greg
Try this code in your .htaccess:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^([^/]+)/?$ /#!/home/$1 [R=302,NE,L]
Once you verify it is working fine, replace R=302 to R=301. Avoid using R=301 (Permanent Redirect) while testing your mod_rewrite rules.
Will this work? Put this in the .htaccess file. Untested
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+) /#!/home/$1 [R=301,NC,L]

.htaccess folder and file name conflict in url rewrite

I have the following htaccess to allow for no file extensions in the url:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ $1.php
My problem is that i have both a file called images.php and a folder called images, so when i use the url: .com/images - it takes me to the images folder, where as: .com/contact - takes me to the correct page.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
With these 2 lines, you say if the test string (in your case 'images') is not a directory and is not a file, rewrite it to images.php. Now, since you have images directory, the second rule is not satisfied and images is rewriten to images.php internaly.
Either change the name of the folder, change the name of the script, or change the .htaccess rules and conditions.
I think if you add before your rule this rule suppose to work ...(but I didn't test it)
RewriteRule ^images/(.*)$ images/$1.php [L]
As Tim Stone suggested, removing the RewriteCond %{REQUEST_FILENAME} !-d line will fix the problem.
Your rules should then look as follows:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ $1.php

Resources