I need to create a .htaccess rewrite. All requests need to redirect to /public/index.php. except for assets. (public/images/, public/css/ etc...). My css and js files have version (style.20180523.css). So the numbers need to get remove from the file name.
Example link:
domain.com/users/123 -> to index.php
domain.com/public/images/logo.png -> All requests which start with public, will remain unchanged If css or js remove a number
Here is my htaccess:
<Files *.php>
Order Deny,Allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files index.php>
Order Allow,Deny
Allow from all
</Files>
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^(?!\/public) public/index.php [L,QSA]
</IfModule>
You need to add a rewrite condition like
RewriteCond %{REQUEST_URI} !^/public/(css|js)/
before your RewriteRule.
This will rewrite everything that is not starting with /public/css or /public/js
Related
So I have set up htaccess to pick up filenames e.g. /page.html and create the url /index.php?page_url=page and it works ok for all my pages but sitemap.xml isn't being found.
Instead it loads a plain html page with no content as it's returning index.php?page_url=sitemap instead of just loading the sitemap file which is in the root of the directory called sitemap.xml
Here is my htaccess file
RewriteEngine on
##### Security #####
## Keep people out of .inc files
<files *.inc.php>
order allow,deny
deny from all
</files>
<files *.inc.html>
order allow,deny
deny from all
</files>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
## Deny index views of directories with no index file ##
Options -Indexes
# Ensure php pages cannot be viewed with the exception of /index.php
RewriteRule ^index.php$ - [L]
# ensure all pages end with a slash if there's no .xxx terminator
RewriteRule ^(([a-z0-9\-]+/)*[a-z0-9\-]+)$ /$1/%{QUERY_STRING [NC,R=301,L]
#fetch pages with no suffix and treat them as if they are html pages
RewriteRule ^([A-Za-z0-9|_|\-|\/]+)/$ /index.php?pageUrl=$1/&contentType=html&%{QUERY_STRING} [L]
#fetch pages with a suffix and treat them as if they are the approriate page type
RewriteRule ^([A-Za-z0-9|_|\-|\/]+).([html|rss|xml|php]+)$ /index.php?page_url=$1&contentType=$2&%{QUERY_STRING} [L]
The .htaccess file is in the root alongside sitemap.xml and robots.txt which also has the full url of the sitemap in it so I'm not sure where I've gone wrong here
I've taken xml out of the last line ([A-Za-z0-9|_|-|/]+).([html|rss|xml|php]+)$ and it works great now
I want to block HTTP access to every file in my project directory except PHP scripts located in the root folder (not subfolders).
My current .htaccess file looks like this :
# Disable Directory Listings in this Directory and Subdirectories
# This will hide the files from the public unless they know direct URLs
Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/(.*)$ api.php/$1 [QSA,L]
</IfModule>
# Deny all files from being accessed with Apache
Order Deny,Allow
Deny from all
# Allow specific PHP files at root
<FilesMatch "/(api|cron|status)\.php$">
Order Allow,Deny
Allow from all
</FilesMatch>
This mostly works, except for the URL rewriting on the api.php script. I've tried changing the FilesMatch regexp to /(api|cron|status)(\.php)?$, but it keeps on throwing me a 403 response.
Anyone can explain to me what I did wrong here ? I'm usually OK with regexp, but this has got me thinking Apache doesn't process them like everyone else...
Deny from all
<FilesMatch "^(api|cron|status)\.php$">
Order Allow,Deny
Allow from all
</FilesMatch>
And I guess make sure your .htaccess is on the root level.
I'm new in SS and I need to moved one website from one web hosting into Godaddy.
Ir order to do that I have installed SS in my local environment in the root folder and everything works smoothly. Then I went to the subdomain and almost everything works well except the detail page. For example:
Home page: http://subdomain.domain.com.au/subdomain/index.php/ - IT WORKS
Product - Tools page: http://subdomain.domain.com.au/subdomain/index.php/products/tools/ - IT WORKS
Tools details page: http://subdomain.domain.com.au/tools/show/slp20xp IT DOESN'T WORK.
If I go to this URL : http://subdomain.domain.com.au/subdomain/index.php/products/tools//show/slp20xp The page is there and working fine. Somehow, on the detail page is trying to go one step backward to the root folder. If I moved this page to the root folder everything works fine.
Any idea what I might be missing? I tried different htacces configuration but none of them seems to work.
### SILVERSTRIPE START ###
<Files *.ss>
Order deny,allow
Deny from all
Allow from 127.0.0.1
</Files>
<Files web.config>
Order deny,allow
Deny from all
</Files>
# This denies access to all yml files, since developers might include sensitive
# information in them. See the docs for work-arounds to serve some yaml files
<Files *.yml>
Order allow,deny
Deny from all
</Files>
ErrorDocument 404 /assets/error-404.html
ErrorDocument 500 /assets/error-500.html
<IfModule mod_alias.c>
RedirectMatch 403 /silverstripe-cache(/|$)
RedirectMatch 403 /vendor(/|$)
RedirectMatch 403 /composer\.(json|lock)
</IfModule>
<IfModule mod_rewrite.c>
SetEnv HTTP_MOD_REWRITE On
RewriteEngine On
RewriteBase '/'
RewriteCond %{REQUEST_URI} ^(.*)$
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !\.php$
RewriteRule .* framework/main.php?url=%1&%{QUERY_STRING} [L]
</IfModule>
### SILVERSTRIPE END ###
In the htaccess of the subdomain, try changing RewriteBase '/' to RewriteBase '/subdomain'
I am having a problem , I am a great supporter of .htaccess , but I have taken a yahoo small business hosting for one of my Project, which currently dont supports .htaccess rewrite, so I am looking for some best option to mimic the same functionality with php instead of .htaccess
So , I can redirect all request to index.php with the following code, Reference
if(basename($_SERVER['REQUEST_URI']) !== 'index.php'){
header("location:index.php");
exit();
}
Now I want to implement other functionality in php too, like denial of directory access, and allowing only css , jss , image file etc direct access.So please suggest me some optimised and feasilble way to achieve this. Here is .htaccess for reference
RewriteEngine on
RewriteBase /
SetEnv APPLICATION_ENV development
#SetEnv FACEBOOK_APP_ID 4343434343
#SetEnv FACEBOOK_APP_SECRET d00b24f1344334833c90f0795ebe
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?url=$1 [L,QSA]
# This denies all web access to your .ini file.
<Files ~ "\.(php|ini|log|htm)$">
Order allow,deny
Deny from all
</Files>
<FilesMatch "^(index\.php)?$">
Allow from All
</FilesMatch>
<files config.base.ini>
order deny,allow
deny from all
</files>
<files errorlogs.log>
order deny,allow
deny from all
</files>
PS :FB SECRET ID AND CREDENTIALS ARE DUMMY
My question is quite simple. I have my main page (www.domain.com/index.php)
Is there a way to redirect the user to /index.php when he only types www.domain.com?
And also remove the index.php from the url when he's on it?
I checked a bit about .htaccess, but none of the tricks seem to do the job.
Thank you!
EDIT
Here's my .htaccess:
# To set your custom php.ini, add the following line to this file:
# suphp_configpath /home/yourusername/path/to/php.ini
DirectoryIndex index.php
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
<Files .htaccess>
order allow,deny
deny from all
</Files>
Options All -Indexes
As you can see, I put DirectoryIndex index.php in it, but doesn't change it :(
Simply put
DirectoryIndex index.php
in your .htaccess
When the user types www.domain.com it'll take index.php as default index page and won't be display in the address
in the Domain control panel mention Start / Index page as index.php.
Usually index.html/htm is the default page.
You will find these option under site proerties.
Redirect / http:/your.domain.php/index.php
RewriteEngine On
RewriteBase / # URL path corresponding to this directory
RewriteRule (^|.*/)index\.php$ $1 [R]