I can't seem to figure this out, I have a directory structure in my root folder like '/state/page--city'. In my htaccess file i redirect all requests that are not directories or files in my root folder to a page.php. So what I would want is to remove the '/state' part from the URL when the users access 'http://example.com/state/page--city/' so that the URL looks like 'http://example.com/page--city/'. Any ideas? Thnx.
.htaccess file:
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* page.php?&[|]v1||%{REQUEST_URI}[|]v2||-[|]v3||%{HTTP_HOST}[|]v4||%{REQUEST_FILENAME}[|]v5||EOL[~|~]= [QSA,L]
Related
I've tried all sorts of ways. I am having trouble redirecting the root .htaccess file to a subdirectory/public file.
Currently, the root redirects to the folder but the path of file shows up in the url.
For example:
website.com/flarum/public should be website.com
...
public_html
-- .htaccess // below
-- flarum
---- public
------.htaccess //default flarum's htaccess
.htaccess
RewriteEngine On
RewriteRule ^$ /flarum/public/ [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/flarum/public/
RewriteRule ^(.*)$ /flarum/public/$1
right now it is showing, website.com/flarum/public where it should be website.com
I useing this code in htaccess:
RewriteRule ^([^/]*)/([^/]*)$ /etel.php?q=$1&n=$2 [L]
This control this
domain.com/etel.php?q=501&n=Beef
to this:
domain.com/501/Beef
But if I open the [partner] folder without index.php the htacces open the etel.php. How can I limit that rewrite rule to the parent folder locked out other folder files?
You may use this rule with these 2 RewriteCond to exclude existing files and directories:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/([^/]+)/?$ /etel.php?q=$1&n=$2 [L,QSA]
In my site when I go to URL such as my-site.com/css or my-site.com/js, then browser displays the folder listing instead of the actual page saved in the database. If I use Options All -Indexes in my htaccess then it says forbidden. I have following rule in my htaccess to load any dynamic page:
RewriteRule ^(.*)$ page.php?url=$1 [QSA,L]
Since I have also folders named css and js in my project, so I think server displays the directory content instead of dynamic page. How can I prevent this conflict. I know if I use a suffix "page" before my page name then it can be sorted out but i don't want to use any parameter before the page url.
EDIT
Here's my complete htaccess file:
# my-site.com
Options +FollowSymlinks -MultiViews
#RewriteBase /
#Enable mod rewrite
RewriteEngine On
DirectorySlash off
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ page.php?category=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)/([^/]+)$ page.php?category=$1&post=$2 [QSA,L]
Since /js and /css are real directories your rewrite rules don't execute because you have this condition:
RewriteCond %{REQUEST_FILENAME} !-d
which means don't run for directories.
You can tweak your .htaccess to this:
Options +FollowSymlinks -MultiViews
RewriteEngine On
# add a trailing slash to directories
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule !/$ %{REQUEST_URI}/ [L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ page.php?category=$1 [QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ page.php?category=$1&post=$2 [QSA,L]
I want the site to be url friendly match, so that the directory / adm (which in my case is the administrative panel) has not url friendlies
my .htaccess
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
I just want to do this I'm learning this rule means in layman commands. htaccess
All your scripts will be redirected to index.php based on below
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
In addition you can specify the folder name, filename which should not follow the above rule. This can be done by adding another rewrite condition statement in your htaccess file.
RewriteCond %{REQUEST_FILENAME} !(img|anyother folders that you want to ignore|anyother folders that you want to ignore|...)
'|' is used to separate each folder name that you want to ignore
So your .htaccess file will have following
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
# For all files not found in the file system, reroute the request to the
# "index.php" front controller, keeping the query string intact
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !(adm|anyother folders that you want to ignore|anyother folders that you want to ignore|...)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]
</IfModule>
Hi I have an admin folder that has pretty much the same custom system as my root folder so I need htaccess to make the URL's look nice so in root I have:
example.com/home and admin should be example.com/admin/home.
My root's htaccess is
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?p=$1 [QSA,L]
This works fine but no matter what I do when I have a copy of this in the admin folder it does not work. I have tried RewriteBase I have tried doing the admin folder from the root htaccess but anything I try always makes the pages 404 or 500 error.
Admin htaccess
Options +FollowSymlinks
RewriteEngine On
RewriteBase /admin/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?p=$1 [QSA,L]
Are you sure that you have set properly admin folder's AllowOverride directive? You can set that in your site's configuration file.