I have transfer my files to dedicated server. I have a restful api for my mobile app. It will route the folder name with parameter. The parameter will be a argument of the function and inputs. I have written the .htaccess file as below. but it's not working. How do i solve this?
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-s
RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.*)$ api.php [QSA,NC,L]
RewriteCond %{REQUEST_FILENAME} -s
RewriteRule ^(.*)$ api.php [QSA,NC,L]
</IfModule>
My result will be :
http://www.domain.com/rest/events it will list the values as json output its not working
But http://www.domain.com/rest/api.php?rquest=events its working. I want above method. how do i solve this
Make sure you place this in DOCUMENT_ROOT/rest/.htaccess
Replace your code with this:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /rest/
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ api.php?rquest=$1 [QSA,L]
Related
I have a problem with the .htaccess file. I have it configured in this way.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)/$ index.php?controller=$1 [L]
Every time I access http://localhost/mvc3/contacto/ I'm accessing http://localhost/mvc3/index.php?controller=contacto, up there it is correct but if the friendly URL I remove the final character / (http://localhost/mvc3/contacto) it returns me to the root page (wampserver server).
Here is explained in video of the problem, what would be happening?
Video ▶️ http://recordit.co/FfXHww1xCv
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule ^(.*)$ index.php?controller=$1 [L]
Remove slash from the rewrite rule and it should work.
may below changes in .htaccess will be helpful for you
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME} -f
RewriteRule ^ ^$1 [N]
RewriteCond %{REQUEST_URI} (\.\w+$) [NC]
RewriteRule ^(.*)$ index.php?controller=$1
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
</IfModule>
I'm trying to hide subfolders from url like this:
localhost/imo/public_html/public/ajuda.php to localhost/imo/ajuda
Its working well if the file exist, if not i get a forbidden access like this:
You don't have permission to access
/imo/public_html/public/public_html/public/public_html...public/contacto.php.php.php.php.php.php.php.php.php.php
on this server.
this is my htaccess file:
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^$ public_html/public/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ public_html/public/$1
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA,NC]
</IfModule>
I already search on stackoverflow and it seems that the rules is causing a loop but the solutions provided didn't work on my case so far. Any help at all would be very aprecciated.
Thank you.
UPDATE
Thanks to #Matthijs Otterloo this is the working htaccess script:
<IfModule mod_rewrite.c>
Options +SymLinksIfOwnerMatch
RewriteEngine On
RewriteRule ^$ public_html/public/
RewriteCond %{REQUEST_URI} !^/public_html/public
RewriteRule ^/?([^/]+)$ /public_html/public/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^(.*)$ $1.php [L,QSA,NC]
</IfModule>
Try something like this in your .htaccess file:
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/public_html/public
RewriteRule ^/?([^/]+)$ /public_html/public/$1 [L]
Best way would be to set-up propper virtual hosts but this should fix it.
I have a URL like http://example.com/index.php/fruit/1a2b3c
I want to get the URI's for which I have written a code.
Now I want to remove the index.php from the visible URL, it should work even when the URL is http://example.com/fruit/1a2b3c and it should still point to index.php
I am on apache2 using PHP 7
Add following code to your .htaccess file.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s(.*)/index\.php [NC]
RewriteRule ^ %1 [R=301,L]
change your .htaccess file to,
RewriteEngine on
RewriteCond $1 !^(index\.php)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [QSA,L]
hope this will work.
I'm trying to create a vanity url for where users profile could easily be viewed by others.
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule .* - [L]
RewriteRule ^(.*)$ http://localhost/test/public/profile.php?username=$1 [NC]
This is the code but each time i use this code in my .htaccess file, i get 500 Internal Server Error and the sub-folder public disappears from my directory. What am i getting wrong? Do i need any to do any configuration first?
It's better to use global rewrite logic:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule . index.php [L]
and in Your index.php catch $_SERVER['REQUEST_URI'] and if user exists so respond if not then pass processing to next procedure.
But if You insist on realization as in question so try this:
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ profile.php?username=$1 [L,QSA]
Check this:
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^profile/([a-zA-Z0-9_\-/]+)$ test/public/profile.php?username=$1 [L,NC]
</IfModule>
However note:
You must have the rewrite engine on to make it work (google a bit for the installation procedure the OS/system you are working)
Put proper RewriteBase directive if you use it from subdirectory.
I have created an app in Laravel.
My initial .htaccess was:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
And it worked properly for the domain api.viglug.org.
After I added the m.forum.viglug.org domain (with the same root directory of api.viglug.org).
At this point was exactly the same to call api.viglug.org and m.forum.viglug.org.
I wanted to use the m.forum.viglug.org for the folder api.viglug.org/mobile so I thought it would have worked with this .htaccess:
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine On
</IfModule>
<IfModule mod_rewrite.c>
RewriteCond %{HTTP_HOST} m\. [NC]
RewriteRule ^(.*)$ index.php/mobile/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>
I was wrong. It keeps returning error 500 if I use m.forum.viglug.org, while api.viglug.org works as expected.
How can I fix this?
The original rewrite only runs on files which do not exist as real files or directories, due to these two conditions:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
Have you tried adding those two conditions above your additional rule?
# Mobile site
RewriteCond %{HTTP_HOST} m\. [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/mobile/$1 [L]
# Normal site
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]