How to remove subdirectories using mod_rewrite in .htaccess - php

All my site url reads
http://example.com/myfolder/main/other/extra/index.php
I want it to rewritten as
http://example.com/index.php

Try the below rule :
Options +FollowSymlinks
RewriteEngine on
rewriterule ^myfolder/main/other/extra/index.php(.*)$ http://example.com/index.php$1 [r=301,nc]

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]

Rewrite rule using htaccess in 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]

Rewrite URL using .htaccess (adding query string)

http://www.naissancebebe.com/index.php?fc=module&module=prenoms&controller=search&gender=boy
I want to rewrite this using .htaccess to this way
http://www.naissancebebe.com/boy.php
so this query string "index.php?fc=module&module=prenoms&controller=search&gender=boy" add in .htaccess file.
here is my code
#RewriteEngine On
RewriteRule ^boy.php /index.php?fc=module&module=prenoms&controller=search&gender=boy [L]
Try :
Options -Multiviews
RewriteEngine On
RewriteRule ^boy\.php$ /index.php?fc=module&module=prenoms&controller=search&gender=boy [QSA,NC,L]

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]

How to redirect url to parent directory with url rewriting

I need to make redirections from a sub-directory to the parent directory.
In other words I have to redirect anything matching
http://exemple.com/portfolio/product1
to :
http://exemple.com/product1
Is there any way to do that with URL REWRITE ?
Thanks
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your .htaccess under DOCUMENT_ROOT directory:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteRule ^portfolio/(.*)$ /$1 [L,R=301,NC]
You want to put this into .htaccess inside the directory that you want to be redirrected
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/parent
RewriteRule ^(.*)?$ http://%{HTTP_HOST}/parent

Categories