/etc/apache2/sites-available/default.conf reads:
<Directory>
Options Indexes FollowSymLinks MultiViews
AllowOverride All
</Directory>
I have mod_rewrite enabled
Under /var/www/sitename
I have my .htaccess file which reads:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
Yet, when access localhost/sitename/directory I get a 404 error
What am I missing here?
Try adding RewriteRule ^(directory)($|/) - [L] above the first RewriteCond so it will exclude the directory from RewriteRule you can add more than 1 directory by seperating them with | like RewriteRule ^(forum|extras)($|/) - [L]
Here is an example:
RewriteEngine On
RewriteBase /
RewriteRule ^(directory)($|/) - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
For people using ubuntu I found this answer to be complete.
https://askubuntu.com/a/48363
try this -
Options +FollowSymLinks
RewriteEngine on
RewriteRule process-id-(.*)\.htm$ process.php?id=$1
Related
i am trying to redirect sub folder installation to root
ie. http://mydomain/auth/login its actually http://mydomain/test/web/index.php/auth/login
works fine with all urls
but not working if i am trying to access http://mydomain getting 403 Forbidden error
note
http://mydomain/index.php to http://mydomain/test/web/index.php is working
http://mydomain to http://mydomain/test/web/index.php is not working
i am looking to access http://mydomain without Forbidden error and /index.php in url
<IfModule mod_rewrite.c>
RewriteEngine On
Options -Indexes
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ /test/web/index.php/$1 [QSA,L]
</IfModule>
First you should exclude any URI start with /test/web/index.php at your code , so t should look like this :
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !/test/web/index.php
RewriteRule ^(.*)$ /test/web/index.php/$1 [QSA,L]
</IfModule>
Then , you could handle error request that passes a rule above .
Moreover , Options -Indexes , in short ,means prevent directory listing when there is no index page at that directory , your code should look like this :
DirectoryIndex /test/web/index.php
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /index [NC]
RewriteCond %{REQUEST_URI} !/test/web/index.php
RewriteRule ^ / [R=301,L,NE]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !/test/web/index.php
RewriteRule ^(.*)$ /test/web/index.php/$1 [QSA,L]
</IfModule>
Note: clear browser cache then test it .
I have written .htaccess files to prevent frontend/web from appearing in url but when I saet links through Url::to it appears in url.
This is my .htaccess in root directory:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
# deal with admin first
RewriteCond %{REQUEST_URI} ^/(admin)
RewriteRule ^admin/assets/(.*)$ backend/web/assets/$1 [L]
RewriteRule ^admin/css/(.*)$ backend/web/css/$1 [L]
RewriteCond %{REQUEST_URI} !^/backend/web/(assets|css)/
RewriteCond %{REQUEST_URI} ^/(admin)
RewriteRule ^.*$ backend/web/index.php [L]
RewriteCond %{REQUEST_URI} ^/(assets|css|js|images)
RewriteRule ^assets/(.*)$ frontend/web/assets/$1 [L]
RewriteRule ^css/(.*)$ frontend/web/css/$1 [L]
RewriteRule ^js/(.*)$ frontend/web/js/$1 [L]
RewriteRule ^images/(.*)$ frontend/web/images/$1 [L]
RewriteRule ^(.*)$ frontend/web/$1 [L]
RewriteCond %{REQUEST_URI} !^/(frontend|backend)/web/(assets|css|js)/
RewriteCond %{REQUEST_URI} !index.php
RewriteCond %{REQUEST_FILENAME} !-f [OR]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ frontend/web/index.php
</IfModule>
This is .htaccess file in frontend/web directory:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
Please help me I have no idea what to do.
Use the following configuration in Apache's httpd.conf file or within a virtual host configuration. Note that you should replace path/to/frontend/web with the actual path for frontend/web.
# Set document root to be "frontend/web"
DocumentRoot "path/to/frontend/web"
<Directory "path/to/frontend/web">
# use mod_rewrite for pretty URL support
RewriteEngine on
# If a directory or a file exists, use the request directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Otherwise forward the request to index.php
RewriteRule . index.php
# ...other settings...
</Directory>
Yii2 Docs
Add below lines in to your .htaccess file and replace /to/base/path/ with your project directory path
RewriteCond %{REQUEST_URI} ^/to/base/path/
RewriteRule ^(.*)$ frontend/web/$1 [L]
You have a lot of questions about basic stuff. what about this
And you can see in them a lot of stuff for ccs and not only
I have the following .htaccess code:
<Directory /var/www/html/angular2-sens>
Options Indexes FollowSymLinks
RewriteEngine On
RewriteBase /angular2-sens
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /angular2-sens/index.html [L]
</Directory>
Now, this code is from some tutorial I found - and I need to change it to fit my webstie structure.
My website is located in mydomain.com/v2
and the directory is /domains/mydomain.com/public_html/v2/
Hope you can help me with this.
I tried to do it myself and failed - returned error 500. (Place .htaccess in the v2 folder)
<Directory />
Options Indexes FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</Directory>
What's wrong?
Try this code in your /v2/.htaccess:
Options +FollowSymLinks
RewriteEngine On
RewriteBase /v2/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.html [L]
<Directory> directive is not allowed in .htaccess.
I have site where
site.com/index.php?page=test (include file test.php from pages folder into index.php)
is replaced by site.com/test
Goal:
If I go to site.com/index.php?page=forum/new_enrty
I want ot make url site.com/forum/new-entry
Problem:
if I open site.com/forum/new-entry it directs me to forum directory to new-entry file directly and not include new-entry into index.php
So far I got this:
<IfModule mod_rewrite.c>
RewriteEngine on
#RewriteBase /cms/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^ index.php [L]
</IfModule>
Replace your code with this:
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.+?)/?$ index.php?page=$1 [L,QSA]
Try this one:
RewriteRule ^([^/]*)$ /index.php?page=$1 [L]
It is possible to rewrite my url using mod_rewrite and htaccess where a user could enter:
http://www.mainsite.com/12345
which the server would translate as:
http://www.mainsite.com/index.php?ID=12345
By also trying to remove the file extension from all pages, (remove .php) it conflicts and causes a never ending redirect:
<IfModule mod_rewrite.c>
Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteRule ^(.*)\.php$ $1 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9a-zA-Z]+)$ index.html?ID=$1 [QSA,NC,L,R]
</IfModule>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([0-9]+)$ index.php?ID=$1