Remove Query string from website url [duplicate] - .htaccess

This question already has an answer here:
Using .Htaccess url redirection
(1 answer)
Closed 8 years ago.
i want to remove query string from my url using htaccess but i cant find any proper solutions
www.mysite.net/index.php?title=Category:Public_Companies&redirect=no&pagefrom=GET+UP
I Want
www.mysite.net/Category:Public_Companies/GET+UP
How can i do this. Any help will be appreciated.

The fast and easy way
.htaccess
RewriteEngine On
RewriteRule ^(.*)/(.*) index.php?title=$1&pagefrom=$2&redirect=no [L]
I create for all characters you need define what character you will be use.
Php file for test .htaccess frendly url
<?php print_r($_GET); ?>

put this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteCond %{THE_REQUEST} \s/+index\.php\?title=([^\s&]+)&redirect=no&pagefrom=([^\s&]+) [NC]
RewriteRule ^ /%1/%2? [R=301,NE,L]
RewriteRule ^([^/.]+)/([^/.]+)/?$ /index.php?title=$1&redirect=no&pagefrom=$2 [L,QSA]

Related

Use the question mark in htaccess mode rewrite

I have a Website which gives Youtube Video download links. I have a Domain like xxyoutube.com. I want to redirect www.xxyoutube.com/watch?v=abcdef to www.xxyoutube.com/watch/abcdef. I used some htacces modrewrite Commands but the "question mark" give me a big problem while using that commands. I need your kindly help. I need rewrite code to redirect first url to second url.
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} \s/+watch\?v=([^\s&]+) [NC]
RewriteRule ^ watch/%1? [R=302,L]
RewriteRule ^watch/([^/]+)/?$ watch?v=$1 [L,QSA,NC]

some issue on rewriting url using htaccess [duplicate]

This question already has answers here:
How can I create friendly URLs with .htaccess?
(8 answers)
Closed 8 years ago.
When user visit "https://www.example.com/api3/SGy7bT" url then i want to load "https://www.example.com/api3/webhook3_index2.php?random=SGy7bT" page. On the browser the url will not change and it will appear like top mentioned url.
My htaccess file is exist on "/api3" folder.
Try:
RewriteEngine On
RewriteBase /api3/
RewriteCond %{THE_REQUEST} /api3/webhook3_index2\.php\?random=([^&\ ]+)
RewriteRule ^ %1? [L,R]
RewriteCond %{REQUEST_FILEAME} !-f
RewriteCond %{REQUEST_FILEAME} !-d
RewriteRule ^(.*)$ webhook3_index2.php?random=$1 [L,QSA]

htaccess url with usernames [duplicate]

This question already has answers here:
Reference: mod_rewrite, URL rewriting and "pretty links" explained
(5 answers)
Closed 8 years ago.
What i wanted to do is first hide all .php extensions in my URL secondly i wanted all users to have there pages with there usernames like www.domain.com/username
however i can easily do the first with this code in my .htaccess.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)$ $1.php
Now how can i do the second part as if somebody goes to this domain www.domain.com/username server will route to www.domain.com/username.php but it should go to URL like www.domain.com/profile.php?id=username.
How can i achieve this?
Something like this, however it will redirect everything after the / to profile.php, so you have to make rules for all other urls before this, if needed.
RewriteRule (.*) profile.php?id=$1

Rewrite from home.php to home [duplicate]

This question already has answers here:
mod_rewrite http://localhost/home/ or http://localhost/home to home.php
(2 answers)
Closed 8 years ago.
I need to rewrite this url:
www.example.com/home.php to www.example.com/home
I write this code in the .htaccess but doesn't work:
RewriteEngine on
RewriteRule ^home$ $home.php [nc]
why ?
Options +FollowSymlinks
RewriteEngine on
RewriteRule ^(.*)\$ home.php [nc]
SHOULD work. Did not test.

Htaccess redirect [duplicate]

This question already has an answer here:
Closed 12 years ago.
Possible Duplicate:
How to rewrite to mobile.myUrl.com if user is mobile? (use Apache or inside Webapp?)
Hi there! I'm trying to write a rewrite rule, that would redirect every address in my domain, to index.php, like this:
RewriteCond %{REQUEST_URI} !=/index.php
RewriteRule .* /index.php
The problem with this code is that in index.php I check whether user came to my website from a pc, or a mobile device, and according to that I redirect him to appropriate version (index.html, or mobi.html) - now since this rule applies I'm stuck in a redirection loop. Pls help stackoverflowers :).
Either you just exclude the pages index.html and mobi.html:
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{REQUEST_URI} !=/index.html
RewriteCond %{REQUEST_URI} !=/mobi.html
RewriteRule .* /index.php
or you can set a GET variable in your redirected url, like header('Location: domain.com/index.html?norewrite'); and then do not rewrite the URL if it contains this variable:
RewriteCond %{REQUEST_URI} !=/index.php
RewriteCond %{QUERY_STRING} !^(.*&)?norewrite(&.*)?$
RewriteRule .* /index.php

Resources