subfolder url get parameter not working in htaccess - php

I have a website like www.abc.com/service/page.php?ids=social. I redirected site to www.abc.com/service/social. But i need to avoid this folder from url.Ex:www.abc.com/social.
Options +FollowSymLinks -MultiViews
RewriteEngine on
RewriteBase /service/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9]+|)/?$ page.php?ids=$1

Simply exclude "service" from the regex match:
RewriteRule ^service/([a-zA-Z0-9]+|)/?$ page.php?ids=$1

Place this code in site root .htaccess (i.e. parent directory of /service/):
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule !^service/ service%{REQUEST_URI} [L,NC]

Related

Why $_GET stills get the last folder that's indicated on my RewriteBase directive

I'm doing a simple MVC from scratch and my project is in /var/www/test_mvc where I have two subfolders: app and public. the public subfolder is where the users will access.
So, in my .htaccess I have this code:
Options -MultiViews
RewriteEngine On
RewriteBase /test_mvc/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]
In the constructor of the Index controller I print the values fro $_GET["url"] and if I request localhost/test_mvc/public/index/greet/name the value that shows is /public/index/greet/name
How can I solve it to get the value index/greet/name?
Change your rule to this:
Options -MultiViews
RewriteEngine On
RewriteBase /test_mvc/public
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^public/(.*)$ index.php?url=$1 [QSA,L,NC]

How to load default index file with .htaccess for variable directory structure in url

Lets say my site structure is like this:
www.mywebsite.com/directory/$variabledirectoryname/$variableproductlink
As you can see in the middle i have 2 variables in the url, but the last is the poduct link. My index.php file stays in www.mywebsite.com/directory/$variabledirectoryname folder. How to load it?
I have this code:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ index.php [L]
But it doesnt work.. Thanks !
You can use this rule in /directory/.htaccess:
RewriteEngine On
RewriteBase /directory/
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/[^/]+/?$ $1/index.php [L]
Update:
You can use this rule in root .htaccess:
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(directory/[^/]+)/[^/]+/?$ $1/index.php [L]

htaccess rewrite rule without changing URL

I have this code in my htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z0-9-/_]+)/?$ http://subdomain.example.com/index.php?id=$1 [L,QSA]
but everytime i go to something like http://subdomain.example.com/test/test
it should resolve to:
http://subdomain.example.com/index.php?id=test/test
which it does, but its changing my URL to be the above and its not keeping the original URL
Remove http:// from your target URL:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} =subdomain.example.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?id=$1 [L,QSA]
I have also corrected your regex in RewriteRule.

PHP URL RE-WRITE

I have a URL http://www.domain.com/products.php?cat=women-clothing-tops and want to re-write it to http://www.domain.com/women-clothing-tops, how do I go about this? Is it just a URL re-write or there are other things I need to do to get it re-written?
Try adding these rules to the htaccess file in your document root:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-z0-9-]+)$ /products.php?cat=$1 [L]
if apache server
.htaccess
update
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . products.php

URL rewrite confusion

i have a htaccess file to help rewrite my url of ../players.php?first_name=Richard&last_name=Marston this gives me the url of ../Richard%20Marston, here is my .htaccess file contents
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ players.php?first_name=$1&last_name=$2
IndexIgnore *
can someone help and amend my current .htaccess file so it reads without the %20 and instead either with no gap such as ../RichardMarston ... or with a - such as ../Richard-Marston for profile pages
Much appreciated
Try this one for Richard-Marston
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)-([^/.]+)$ players.php?first_name=$1&last_name=$2
You need some kind of separator between first name and last name. If you have only one rule, you can remove players/ in rewrite rule:
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^players/([^/]+)/([^/]+)$ players.php?first_name=$1&last_name=$2
IndexIgnore *
It will rewrite URLs like players/Richard/Marston to players.php?first_name=Richard&last_name=Marston.

Categories