I am using Slim php framework, having no .htaccess file in root folder I can call the pages
like /index.php/pagename
but if I upload the following .htaccess file in the root folder I always get 403 Forbidden error like You don't have permission to access /hello on this server.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
Try changing your rule to this:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php/$1 [L]
Then you can use a URI /hello which will be rewritten to /index.php/hello.
Please review the Route URL Rewriting
section of the Slim documentation. The .htaccess provided there is different than those posted here.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
Related
I have folder strcture like below
-folder
--text
---index.php
and I have a URL like below
https://example.com/folder/test/index.php?slug=slugname
I added below code in the htaccess to rewrite the URL.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?slug=$1 [QSA,L]
So now my URL is
https://example.com/folder/test/slugname
I have to get the slugname on my php page and I tried echo $_REQUEST['slug']; and echo $_GET['slug']; but I am getting
slugname.php
I want only my slugname.
Please keep following .htaccess Rules file besides your folder named folder and try following rules. Please make sure to clear your browser cache before testing your URLs.
RewriteEngine On
RewriteBase /folder/test/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)/?$ index.php?slug=$1 [QSA,L]
I want to have a single-page app, but only within a sub URL like:
//The following would all be valid, but handled by the "index.html"
//at http://www.test.com/webapp
http://www.test.com/webapp
http://www.test.com/webapp/settings
http://www.test.com/webapp/start
I want all the URLs to look exactly like above, but be handled by: http://www.test.com/webapp/index.html.
I also want the following URLs to not be handled by that page:
http://www.test.com
http://www.test.com/contact
http://www.test.com/about
How do I do this?
REGULAR SINGLE_PAGE HTACCESS
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.html [QA,L]
</ifModule>
Just adding answer for reference.
The commnet from #Croises:
"The same (with [QSA] not [QA]) but in the webapp directory"
Worked for me.
The ".htaccess" must be on the subdieretory.
Example working ".htaccess":
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) index.html [QSA,L]
</ifModule>
The only diference is "[QA,L]" to "[QSA,L]"
The answer marked as good didn't work for me. Below my solution:
1) Create .htaccess in the folder where you place your app
2) Paste the code below
3) Change folder_name to your folder name.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /folder_name/
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /folder_name/index.html [L]
</IfModule>
I'm currently using Angular2 with Apache and I have a problem: when I use routing and navigate through pages, template syntax doesn't work, I just get an empty space in the place where {{}} is in the template. Also ngOnInit seems to be not working. When I use lite-server everything works fine.
EDIT1: I'm trying to run an example from developer's guide on routing: https://angular.io/docs/ts/latest/guide/router.html
https://angular.io/resources/live-examples/router/ts/plnkr.html
EDIT2: I'm also using CodeIgniter 3 and it already uses the following .htaccess file:
RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
It could be an issue with redirects/not-found files.
Try adding .htaccess file:
# BEGIN ServeStatic
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.html$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]
</IfModule>
# END ServeStatic
My .htaccess file is:
RewriteEngine on
RewriteRule (.*) index.php?_url=$1 [QSA,L]
It works perfectly in most cases. But if the requested url exists as a real folder, it goes crazy.
For example when i request /random it is rewritten to index.php?_url=random with status code 200, but for /static (which is an existing directory on the web server) it gives a 301 redirect to /static/?_url=static
use this below code for .htaccess
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ http://%{HTTP_HOST}/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
</IfModule>
If you want to exclude existing files and directories from being rewritten, do so with a RewriteCond
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?_url=$1 [QSA,L]
I have the current setup in my .htaccess file:
<ifModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index
RewriteRule ^ index.html [QSA,L]
</ifModule>
It redirects any trafic to unexisting files or folders to index.html.
However, I would like to make an exception to the rule:
Any request made to locales/non-existing.file should return proper 404.
How can I do that?