Hide get parametres - php

Get:
https://xxx.ru/page/?page=update-1/
how to show:
https://xxx.ru/page/update-1/
I tried does not work
.htaccess
RewriteBase /
RewriteEngine on
RewriteRule ^page\/(.*?)/?$ page/?page=$1 [L,QSA]

You can use:
RewriteEngine on
RewriteBase /
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} \s/+page/\?page=([^\s&]+) [NC]
RewriteRule ^ /page/%1? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^page/(.+)$ page/?page=$1 [L,QSA,NC]

Use this:
RewriteEngine On
RewriteRule ^page/([^/]*)$ /page/?page=$1 [L]
It will give you the following URL:
https://xxx.ru/page/update-1/

Related

clean url with .htaccess but with only one url

i'm using .htaccess to create clean urls.
here is a piece of .htaccess file:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(/$|\.)
RewriteRule (.*) %{REQUEST_URI}/ [R=301,L]
RewriteRule ^posts/page/([0-9]+)/$ posts.php?page=$1
RewriteRule ^posts posts.php
it works fine but problem is both urls work!
is there a way to only make site.com/posts/ work and return 'not found' on site.com/posts.php(or redirect to site.com/posts/)
think i read somewhere two urls for the same page is bad for seo.
You can create a rewrite rule that returns 404 HTTP code on every ".php" URL :
RewriteRule .*\.php$ - [R=404]
This is working fine for me. Hope it will work fine for you as well.
RewriteEngine On
Options -Multiviews
#For rewriting request to posts.php
RewriteCond %{REQUEST_URI} ^/posts/?$
RewriteRule .* /posts.php [L,END]
#For returning 404 on directly accessing /posts.php
RewriteCond %{REQUEST_URI} ^/posts.php$
RewriteRule .* - [R=404,L]
To redirect /posts.php to /posts you can use this
RewriteEngine on
RewriteCond %{THE_REQUEST} /posts\.php [NC]
RewriteRule ^ /posts [NE,L,R]
#Your other rules
If you want to redirect the orignal request to 404 , change the RewriteRule line to this
RewriteRule ^ - [R=404,L]

How to use mod_rewrite to remove a part of a domain

I've this url:
example.com/de/type/villen/
It bothers me that my url contains the /type/. Is there an option to remove this string from my URL?
So someone goes to the URL /de/type/villen and NOT redirect to /de/villen/.
Only display in the browser /de/villen/.
Is that possible?
You can use this code in your DOCUMENT_ROOT/.htaccess file:
RewriteEngine On
RewriteBase /
RewriteCond %{THE_REQUEST} /(de)/type/(villen)/ [NC]
RewriteRule ^ %1/%2 [R=302,L,NE]
RewriteRule ^(de)/(villen)/?$ $1/type/$2 [L,NC]
Try
RewriteEngine On
RewriteRule (.*)/type/(.*) /$1/$2 [L]

Rewrite url not working in htaccess

I have website. I just want to rewrite url using .htaccess
Here is the code which I want to rewrite:
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} /search_data.php\?keywords=([^&]+)&f=([^\s&]+) [NC]
RewriteRule ^/search_data.php/?$ /search/%1/%2? [R=301,L,NC]
this the current url
http://localhost/mywbsite/search_data.php?keywords=one+piece&f=149
I want to convert this to this
http://localhost/mywbsite/search/one-piece/149
I tried above code but its not working please help me
QUERY_STRING is only used to match query string without URI.
You need to use:
Options -MultiViews
RewriteEngine On
RewriteBase /mywbsite/
RewriteCond %{THE_REQUEST} /search_data\.php\?keywords=([^&]+)&f=([^\s&]+) [NC]
RewriteRule ^ search/%1/%2? [R=301,L]
RewriteRule ^search/([^/]+)/([^/]+)/?$ search_data.php?keywords=$1&f=$2 [QSA,L,NC]

URL Rewriting with multiple parameters without changing URL

I want to rewrite my URL
From:
https://example.com/fr/transporter/transporterPublicProfile.php?profil=1927&token=xnbjfgh4534534534dgfsdsd4
To:
https://example.com/fr/profil-des-transporteurs/1927/xnbjfgh4534534534dgfsdsd4
When ever a user visit this URL:
https://example.com/fr/transporter/transporterPublicProfile.php?profil=1927&token=xnbjfgh4534534534dgfsdsd4
It should appear like this:
https://example.com/fr/profil-des-transporteurs/1927/xnbjfgh4534534534dgfsdsd4
And if a user visit this URL:
https://example.com/fr/profil-des-transporteurs/1927/xnbjfgh4534534534dgfsdsd4
Its should remain as it is.
What I have tried so far is:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /fr/
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /fr/transporter/transporterPublicProfile\.php\?profil=([^\s&]+) [NC]
RewriteRule ^ fr/profil-des-transporteurs/%1? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^profil-des-transporteurs/([^/.]+)/?(.*)$ transporter/transporterPublicProfile.php?profil=$1&token=$2 [L,QSA,NC]
RewriteBase /
#RewriteRule ^/fr/shipper/(.*)$ https://example.com/fr/$1 [L,R=301]
#RewriteRule ^login.php https://example.com/fr/shipper/login.php [L]
RewriteRule ^index\.html /index\.php......................
The problem in above .htaccess is it works fine with one parameter i.e profil
. But when I get token in URL, it doesnt work.
What will be the correct .htaccess code for this scenario?
You need to have new set of rules for new parameter:
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /fr/
# external redirect from actual URL to pretty one
RewriteCond %{THE_REQUEST} /fr/transporter/transporterPublicProfile\.php\?profil=([^\s&]+)&token=([^\s&]+) [NC]
RewriteRule ^ profil-des-transporteurs/%1/%2? [R=302,L,NE]
RewriteCond %{THE_REQUEST} /fr/transporter/transporterPublicProfile\.php\?profil=([^\s&]+) [NC]
RewriteRule ^ profil-des-transporteurs/%1? [R=302,L,NE]
# internal forward from pretty URL to actual one
RewriteRule ^profil-des-transporteurs/([^/.]+)/([^/]+)/?$ transporter/transporterPublicProfile.php?profil=$1&token=$2 [L,QSA,NC]
RewriteRule ^profil-des-transporteurs/([^/.]+)/?$ transporter/transporterPublicProfile.php?profil=$1 [L,QSA,NC]
RewriteRule ^index\.html /index\.php [L]

URL Rewrite for multiple pages but same query

As of now I have one generic query "view" which I'll use on most pages...
My rewrite is:
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ $1.php?view=$2 [L]
My url is:
classroom.php?view=creation
I want it to look like:
classroom/creation
I have it working but it screwed up other urls
dashboard.php was just /dashboard
but broke when I did the first rewrite rule...
These things are a pain to understand.
My Question is how can i have /dashboard, /classroom, /classroom/creation work?
EDIT: I got it working with:
RewriteRule ^([a-zA-Z0-9_-]+)$ $1.php [L]
RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/?$ $1.php?view=$2 [L]
The first 2 rules are for external redirect, which turns .php into a directory like format rest of the rules are for the internal redirect which keeps the pretty URL and doesn't show the redirect.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
# Redirect /classroom.php?view=creation to /classroom/creation
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+classroom\.php\?view=([^\s]+) [NC]
RewriteRule ^ /classroom/%1? [R=302,L]
# Redirect /classroom.php to /classroom and /dashboard.php to /dashboard
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/+(classroom|dashboard)\.php [NC]
RewriteRule ^ /%1 [R=302,L]
# Internally forward /classroom/creation to /classroom.php?view=creation
RewriteRule ^classroom/(.*)/?$ /classroom.php?view=$1 [L,QSA,NC]
# Internally forward /classroom to /classroom.php and /dashboard to /dashboard.php
RewriteRule ^(classroom|dashboard)/?$ /$1.php [L,QSA,NC]

Categories