URL rewrite confusion - php

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.

Related

subfolder url get parameter not working in htaccess

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]

.htaccess rewrite rule for specific URL

When user hit a URL like this
www.mydomain.com/premium-pro/somepage.html
It should map to the
www.mydomain.com/myfile.php
and I should be able to access somepage.html as a $_GET parameter in myfile.php
I have .htaccess under mydomain.com but very new to rewrite rules and not sure what kind of rule should be written there. I did research on this but didn't get succeed.
Please help
Try with below rule in root, I've taken a var variable for $_GET data.
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} ^/premium-pro/(.+)
RewriteRule ^ myfile.php?var=%1 [L]
Try this:
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule myfile.php ./premium-pro/somepage.html

.htaccess RewriteRule with file extension

This question might be a duplicate but i'm trying to do a URL Rewrite by converting :
http://example.com/file.php?f=the_file_name&ext=the_file_extension
to
http://example.com/video2.mp4
I tried the following RewriteRule script but it change also others folders :
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+).([^/]+)$ file.php?f=$1&t=$2 [L]
I couldn't get them work.. What am I doing wrong? and how can I make it work?
Thanks !
Dot is special regex symbol and it needs to be escaped:
Options +FollowSymLinks
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^.]+)\.([^/]+)$ file.php?f=$1&t=$2 [L,QSA]

Mod Rewrite Htaccess for Fake Directories

I am trying to create fake directories to redirect specific parameters to specific subdirectories as such:
From: www.example.com/username
To: www.example.com/posts?uid=alex
From: www.example.com/p/1234
To: www.example.com/posts?url=1234
It is somehow more complicated example from the rest questions with the same subject on stackoverflow and most answers do not give an explanation on how it works, thus I am not able to come into a conclusion on how I could solve this.
Try:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^p/([^/]+)$ /posts?url=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)$ /posts?uid=$1 [L]
First, you need to make all of your links look like this:
www.example.com/username
www.example.com/p/1234
The rewrite rules above will match the /p/1234 (via ^p/([^/]+)$) and /username (via ^([^/]+)$) and internally rewrite them to the /posts URI. Note that this will not change the URL in the browser's location bar, as that is an external redirect. If someone enters www.example.com/posts?uid=alex, the URL will be unchanged.
Enable mod_rewrite and .htaccess through httpd.conf and then put this code in your DOCUMENT_ROOT/.htaccess file:
Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^p/([^/]+)/?$ /posts?url=$1 [L,QSA,NC]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ /posts?uid=$1 [L,QSA,NC]

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

Categories