Rewrite rule using htaccess in PHP - php

In my application we have write root directory name(gaming) statically in coding on some pages which are showing as link in GUI. Now whenever I am trying to click on such URLs its redirect me on url1 which is not accessible for me. So is there any possible ways in which I can access url1 without remove such statically name throughout application?
URL 1 :
http://abc:8089/gaming/app/test/unique_testing.php
URL 2 :
http://abc:8089/app/test/unique_testing.php
I have tried some htaccess overwrite rules but it's not working for me.
My current htaccess looks like below :
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^gaming(/.*|)$ /$1 [L,NC]
Structure :
/var/www/html/gaming/app/test/unique_testing.php
/var/www/html/gaming/.htaccess

Inside root /gaming./.htaccess you can use this rule:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteRule ^app(?:/.*)?$ /$0 [L,NC]

Please use this rules in your .htaccess
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^app/(.*)$ /$1 [L,NC,R]

Related

htaccess rewrite rule knowledge

I want to rewrite the url of mysite with help of htaccess. My website url which I need to rewrite is given below.
http://getallfreedownloads.com/category.php?slug=business_directory_listing
Result needed
http://getallfreedownloads.com/business_directory_listing or http://getallfreedownloads.com/business_directory_listing/
I have used the below code for rewrite rule in my htaccess file
RewriteEngine On
RewriteRule ^([^/]*)$ /category.php?slug=$1 [L]
Please guide me what I can do to make it work fine.
Note: After adding rewrite rule I have removed the " category.php?slug= " from the a Tag
I will be thank full to you all.
try this once.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^/category.php?slug(.*)$ /$1 [L,NC,R]

How to modify this URL in .htaccess?

I want to modify URL with a check.
If there exists experiment as second folder, then do this
{site}.com/dashboard/experiment/closed/.../
to
{site}.com/experiment/closed/.../
If no experiment found in path, then don't do anything. For eg
{site}.com/dashboard/ex-view/closed/.../
How do I achive this using htaccess. I'm using Laravel 5.1.
This is what I tried but it doesn't meet the second condition.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^experiment/(.*)$ /$1 [L,NC,R]
You can try this rule in the .htaccess in the root. The should only affect URL with experiment as the second folder.
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^.+/experiment/(.*)$ /experiment/$1 [L,NC,R]

Simple RewriteRule do not work at php/apache in htaccess

I do not know why, but this simple Rule will not work.
<IfModule mod_rewrite.c>
Options -MultiViews
RewriteEngine On
RewriteBase /
RewriteRule ^rubbellos\.png/$ rubbellos/rubbelbild_png.php [NC,L]
RewriteRule ^rubbellos\.css/$ rubbellos/rubbellos_css.php [NC,L]
</IfModule>
If I copy the xyz/rubbellos/rubbelbild_png.php to browser it is OK.
My approach is to bring the request of rubbellos.png to the .php-file. But I get a file not found.
Thx for any hint in advance.
You have 2 errors:
use a RewriteBase since you're talking about a subdirectory /xyz/ in your question.
disable MultiViews option to avoid unexpected behaviour with rubbellos (virtual file and existing directory).
You can replace your current code by this one in your htaccess (which has to be in /xyz/ folder)
Options -MultiViews
RewriteEngine On
RewriteBase /xyz/
RewriteRule ^rubbellos\.png$ rubbellos/rubbelbild_png.php [L]
RewriteRule ^rubbellos\.css$ rubbellos/rubbellos_css.php [L]
Note: don't forget to replace xyz by your real subdirectory's name

Htaccess rewrite no extension or slash

I want every file on my server like this
"mywebsite.com/video?id=vgIjgt863_53",
I have php so at the moment it would look like this
"mywebsite.com/video.php?id=(id)"
I need this in htaccess
Put your htaccess in root folder with this code
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteCond %{QUERY_STRING} ^id=(.+)$
RewriteRule ^video$ /video.php?id=%1 [L]

Using .htaccess to redirect to relative address

I am very new to URL rewriting using .htaccess and I would like to redirect anyone entering the domain below
http://domain.tld/admin
to be redirected to
http://domain.tld/index.php?section=admin
but without including the full address. This is the code I am using but it doesnt seem to work
Options -Indexes
Options +FollowSymLinks
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^admin /index.php?section=admin
</IfModule>
Where Im I going wrong?
Thanks
You can use this more correct regex rule with L flag:
Options +FollowSymLinks -Indexes
RewriteEngine On
RewriteBase /
RewriteRule ^admin/? index.php?section=admin [L,QSA,NC]

Categories