I have home.php as a directory index file.
This can be accessed like: http://localhost/joacmedia/home.php
How do I make the server point to the same home.php if user type http://localhost/joacmedia/index.php
.htaccess file looks like this:
Options -Indexes
DirectoryIndex home.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ home.php?url=$1 [L,QSA]
Just rewrite the index.php to home.php
RewriteRule ^index.php$ home.php [L]
Your htaccess should look like the following with these settings
Options -Indexes
DirectoryIndex home.php
RewriteEngine On
RewriteRule ^index.php$ home.php [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ home.php?url=$1 [L,QSA]
Keep your htaccess file besides joacmedia folder and try following rules.
Please make sure to clear browser cache before testing your URLs.
RewriteEngine ON
RewriteRule ^joacmedia/index\.php home.php [QSA,NC,L]
Related
I am making a small cms in php. Through htaccess I would like to delete and block all extensions (.php .html. Htm etc.) and add a / at the end of the url.
ex. www.miosito/ article-name/
Options -Indexes
DirectoryIndex home.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^.*$ core.php
this is my current htaccess.
Sorry for my bad English and thank you very much in advance
With your shown samples/attempts, could you please try following htaccess Rules file. Please make sure to clear browser cache before testing your URLs.
RewriteEngine ON
##Excluding Indexes and MultiViews options here.
Options -Indexes -MultiViews
##Rule for url http://localhost:80/test here.
RewriteRule ^(test)/?$ $1/category [R=301,L]
RewriteRule ^(test/category)/?$ $1.php [NC,L]
##Rule for forbidding html OR htm OR php extension files.
RewriteRule \.(html|php|Htm)/?$ - [F,NC,L]
##Rule for adding / at end of urls.
RewriteCond %{REQUEST_URI} /+[^\.]+$
RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
##Rules for non-existing pages to be served here.
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ core.php [QSA,L]
Try out this code in site root .htaccess after completely clearing your browser cache:
Options -Indexes
DirectoryIndex home.php
RewriteEngine On
# block direct access to .php, .html, .html extensions files
RewriteCond %{THE_REQUEST} \.(html?|php)[?\s/] [NC]
RewriteRule . - [F]
## Adding a trailing slash
RewriteCond %{ENV:REDIRECT_STATUS ^$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule [^/]$ %{REQUEST_URI}/ [L,NE,R=301]
# core handler
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . core.php [L]
I'm trying to rewrite URLs using htaccess. The idea behind this is quite simple:
Once a visitor visits https://example.com/pineapples, the browser should load https://example.com/index.php?page=pineapples instead while remaining the original URL.
This should only happen when a file exists in /pages/ with the name of the requested URL, in this case pineapples.php.
This also counts for subdirectories: https://example.com/pineapples/flamingos should redirect to https://example.com/index.php?page=pineapples/flamingos when the file exists in /pages/, in this case /pages/pineapples/flamingos.php, where pineapples is a subdirectory.
Now I've tried to do this, but it's very buggy. It doesn't work for subdirectories as explained above, and it seems to work for all the directories, instead of just /pages/.
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(css|js|jpg|png|gif|svg)$ [NC]
RewriteCond %{REQUEST_URI} !^/pages(/|$)
RewriteRule ^([^/]+/[^/]+/). /$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]
If someone please can help me out get this to work, I will be very grateful!
This question has been answered using the following htaccess.
Options -Indexes +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} !\.(css|js|jpg|png|gif|svg)$
RewriteRule ^(ajax|assets|auth)($|/) - [L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?page=$1 [L,QSA]
You can't check REQUEST_FILENAME because in your case it has to be in pages
so you may want to try
Options -Indexes
Options +FollowSymLinks
RewriteEngine on
RewriteLog /path/to/log
RewriteLogLevel 5
RewriteCond %{REQUEST_URI} !\.(css|js|jpg|png|gif|svg)$ [NC]
RewriteCond %{REQUEST_URI} !^/pages(/|$)
RewriteRule ^([^/]+/[^/]+/). /$1 [R=301,L]
RewriteCond %{DOCUMENT_ROOT}pages%{REQUEST_URI}.php -f
RewriteRule ^(.+)$ index.php?page=$1 [L,QSA]
Also I have enabled rewrite log, so in case it doesn't work, please post the logs your get
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've set up an htaccess file in order to create a small routing structure where urls redirect to index.php. I want to add an exception where if the user types in "/admin" and anything after, the url instead redirects to admin.php.
htaccess -
RewriteEngine On
RewriteBase /
RewriteRule ^admin/?(.*)$ admin.php?page=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
Example: http://mysite.com/admin/settings/ should lead to admin.php?page=settings, while http://mysite.com/about/ should lead to index.php (not using any parameters here). Regexp is really not my cup of tea, especially when there are multiple conditions to consider. Ideas?
Edit: ^admin/([^/]*)/? solved it.
You may try this in one .htaccess file in root directory:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !admin\.php [NC]
RewriteRule ^admin/([^/]*)/? /admin.php?page=$1 [NC,L]
RewriteCond %{REQUEST_URI} !/admin/ [NC]
RewriteRule .* /index.php [NC,L]
For permanent redirection, replace [NC],L] with [R=301,NC,L]
I have the htaccess file
Options -Indexes +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*[^/])/?$ /index.php?p=$1 [L,QSA]
How can this be changed to force requests to /sys-admin to be redirected into index.php even if it does exist (file or directory)?
Add another rule set:
RewriteCond %{REQUEST_URI} /sys-admin*$
RewriteRule ^(.*[^/])/?$ /index.php?p=$1 [L,QSA]