I have to redirect URL with Upper Case parameter to URL with Lower Case parameter.
Since I don't have access to httpd.config file, help me with some pieces of lines to do it in .htaccess file.
For example:
www.domain.com/Whatsapp-For-Business-A-Beginners-Guide
to
www.domain.com/whatsapp-for-business-a-beginners-guide
Thanks in advance.
If you have the opportunity to use php:
You can do that. in the .htaccess (before actual RewriteRule):
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule [A-Z] /linkChange.php?l=%{REQUEST_URI} [L]
and in linkChange.php :
<?php
$link = $_GET['l'];
$newlink = strtr($link," ABCDEFGHIJKLMNOPQRSTUVWXYZ","-abcdefghijklmnopqrstuvwxyz");
header("Location: http://www.exemple.com". $newlink,TRUE,301); exit;
?>
Related
well, i have a question, is there any possible chance to pass parameters from a tag and bring into?
i mean i have the a tag:
sent to $value categories
and in rewrite rule i don't know if i can send an random value
RewriteRule ^CATEGORIES index.php?page=categories [NC,L]
this is my actual CATEGORIES and i want to pass a value from a tag and to show like
RewriteRule ^CATEGORIES index.php?page=categories&anothervalue= [NC,L]
localhost/CATEGORIES/$value not like localhost/CATEGORIE?var = $value
and $value to be anothervalue value
Without messing up all my styles!
I work in localhost!
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^\.]+)/([^\.]+)$ index.php?page=$1&value=$2 [NC,L]
Test :
URL : localhost/mycategory/test
index.php
echo $_GET["page"]
echo $_GET["value"]
Following rule doesn't work for subfolder rewriting.
RewriteRule ^cat/([0-9a-zA-Z]+) cat.php?id=$1
RewriteRule ^cat/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) cat.php?id=$1&sid=$2
For example With this rule
<?php
$id='News';
$sid='Politics';
?>
..
In next page, while echoing $_GET['sid'], it doesn't work
Notice: Undefined index: sid in ...
But this rule
RewriteRule ^cat/([0-9a-zA-Z]+)/([0-9a-zA-Z]+) cat.php?id=$1&sid=$2
works, if only there is two querystring parameters
..
but it generate ERROR 500 if there is only one parameter
<a href="cat/<?php echo $id?>>..</a>
Try with below,
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^cat/([0-9a-zA-Z]+)$ cat.php?id=$1 [L]
RewriteRule ^cat/([0-9a-zA-Z]+)/([0-9a-zA-Z]+)$ cat.php?id=$1&sid=$2 [L]
If I have an URL like this :
http://www.example.com/book.php?translate=id&surah=1&verse=1&and=4&audio=on&hl=yes
and I want to reqrite to new URL like this :
http://www.example.com/quran/id/1/1/4/on/hl/
how to do this in htaccess?
If by the hl you meant yes this is what you want:
RewriteEngine On
RewriteRule ^quran/?([A-Za-z0-9]+)?/?([A-Za-z0-9]+)?/?([A-Za-z0-9]+)?/?([A-Za-z0-9]+)?/?([A-Za-z0-9]+)?/?([A-Za-z0-9]+)?/?$ book.php?translate=$1&surah=$2&verse=$3&and=$4&audio=$5&hl=$6 [NC,L]
TO use it in php you can modify put in the htaccess
Options +FollowSymLinks
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteRule ^.*$ ./index.php
And in the index.php
<?php
#In here you remove the path you don't want
$request = str_replace("/envato/pretty/php/", "",
$_SERVER['REQUEST_URI']);
#get the params by splitting
$params = split("/", $request);
?>
I don't know you use which version,but You can get that in documents
then you need set "URL_MODE"
I've searched for other solutions to rewriting a URL using the .htaccess file at the root of my server, but the language is pretty confusing to me, and I can't seem to get it to work. How would I go about changing:
http://domain.com/share.php?media=059ogbuq70
to:
http://domain.com/059ogbuq70
I found code similar to this, and tried it, but it didn't seem to work:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^media=([0-9]+)$
RewriteRule ^$ share.php?media=$1 [QSA,L]
My PHP:
<?php
$media_id = $_GET['media'];
$url = file_get_contents("https://api.wistia.com/v1/medias/" . $media_id . ".json?api_password=my_key");
$json = json_decode($url, true);
$name = $json[name];
$origimg = $json['thumbnail'][url];
list($image, $size) = explode('?', $origimg);
$video = $json['assets'][5][url];
?>
I then echo the variables where I need them on my page.
Thank you!
To internally rewrite "pretty" URLs so that query strings are passed to PHP, I recommend the following .htaccess file:
RewriteEngine on
RewriteRule ^([^/]+)/?$ share.php?media=$1 [L]
The regex matches:
One or more characters that are not a backslash, optionally followed by a backslash.
Everything but the optional trailing slash are captured in $1 and rewritten as the "media" query string variable.
For example:
http://domain.com/059ogbuq70/
rewrites internally to
http://domain.com/share.php?media=059ogbuq70
Which means that:
$_GET['media'] = 059ogbuq70
You might find this mod_rewrite cheat sheet helpful for building your regex.
Also, you can test your rewrites here.
You need two rules for what you are trying to do. You can place this in the file called .htaccess
RewriteEngine on
#redirect all old URLs to the new rewritten URL
RewriteCond %{THE_REQUEST} ^GET\ /+share\.php\?media=([^&\ ]+)
RewriteRule ^ /%1? [R=302,L]
#rewrite folder path internally to share.php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ share.php?media=$1 [QSA,L]
On this website and on wamp localhost
http://www.aproapetot.ro/page.php?categ_id=1&id=1
http://localhost/aproapetot-backup/page.php?categ_id=1&id=1
I tried to build the .htaccess, but without any success.
This is what I wrote for online website:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^page-([0-9]+).html$ page.php?categ_id=$1
RewriteRule ^page\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
and this for localhost
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /aproapetot-backup/
RewriteRule index.php index.html
RewriteRule ^page-([0-9]+).html$ page.php?categ_id=$1
RewriteRule ^page\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
</IfModule>
Someone please give a little help.
It's a website with jokes so after .ro/page.php?categ_id=1&id=1 I have a category(1) and subcategory(1).
I want to have like this
.ro/jokes/doctors instead of how is now.
I'm not entirely sure what you want based upon the htaccess content, but what I do understand is that you want /jokes/doctors is rewritten to /pages.php
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !pages.php [NC]
RewriteRule ^(.*)$ /pages.php [L]
The above code will rewrite all requests to pages.php, as long as:
%{REQUEST_FILENAME} "!-f": The file itself does not exist on the server.
%{REQUEST_FILENAME} !pages.php: The request is not made to pages.php (meaning that it already has been rewritten)
Finally you can use PHP to obtain the parameters using:
/* Get all parameters from the URL */
$_GET['path'] = rawurldecode( $_SERVER['REQUEST_URI'] );
/* Remove double slashes and backslahses and convert all slashes and backslashes to '/' */
$_GET['path'] = preg_replace( array('#[/\\\\]+#', '/(\/\.)+(\/)/'), '/', $_GET['path']);
$_GET['path'][0] should contain "jokes"
$_GET['path'][0] should contain "doctors"
==edit==
Redirecting using htaccess (not the best method)
Redirect 301 /page.php?categ_id=6&id=0 /anecdotes
Redirect 301 /page.php?categ_id=1&id=1 /jokes/doctors
PHP (or other server side script). You can perform a check if the url is in fact having numbers (see $_SERVER['REQUEST_URI']) and ifso, add some header redirection to your page.
<?PHP
header('Location: www.aproapetot.ro/' . $cat . '/' . $subcat );
?>