rewrite url with slash using htaccess - php

Hello someone pls help me
I have this url which is dynamic
productSearch.php?id_category=8&id_size=23&id_colour=93
and i have to do this in
productSearch/8/23/93
i have try
RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/(.+)\.php[^\s]* [NC]
RewriteRule ^ /%1 [R=301,NE,L]
RewriteCond %{THE_REQUEST} \s/+id_category(?:\.php)?\?id=([0-9]+) [NC]
RewriteRule ^ id_category/%1? [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_URI}.php [QSA,NC,L]
its remove .php only but not putting slash.
Pls some one give me some idea

Try this
RewriteEngine On
RewriteRule productSearch/(\d+)/(\d+)/(\d+)$ productSearch.php?id_category=$1&id_size=$2&id_colour=$3 [L]

RewriteEngine On
RewriteBase /
Options -MultiViews
RewriteRule ^productSearch/([^/]*)/([^/]*)/([^/]*)$ productSearch.php?id_category=$1&id_size=$2&id_colour=$3 [L]
Try this. Put in your url following links: lala
If you want that only a numeric path will be rewritten you could use ([0-9]+) instead of ([^/]*)

Related

Remove a specific file name using htaccess

I have not enough experience in writing rules in .htaccess.
My site url is like
http://exampletest.com/detail.php?i=my-url
I want to rewrite that url to
http://exampletest.com/my-url
What I have tried so far:
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} /detail\.php\?i=([^\s&][A-Za-z0-9-]+) [NC]
RewriteRule ^ detail %1? [R=302,L]
That makes me able to access my site using:
http://exampletest.com/detail/my-url
But I want to omit detail from url as well.
You should redirect internally as well so your code should looks like this :
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} /detail\.php\?i=([^\s&][A-Za-z0-9-]+) [NC]
RewriteRule ^ %1? [R=302,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ /detail.php?i=$1 [L]
Try this:
RewriteEngine on
RewriteBase /
RewriteCond %{THE_REQUEST} /detail\.php\?i=([^\s&][A-Za-z0-9-]+) [NC]
RewriteRule ^ %1? [R=302,L]

Display Pretty URL in browser

I can make the following URL:
example.com/video1
redirect to:
example.com/video/video1.php
but I would like it to display:
example.com/video1
in the browser but it is not.
It is displaying:
example.com/video/video1.php
And when I go to URL:
example.com/video/video1.php
it should display
example.com/video1
in the browser but it is displaying:
example.com/video/video1.php
How do I do this?
Here is what I am using:
RewriteEngine On
RewriteRule ^video1 /videos/video1.php [QSA,NC,L]
RewriteRule ^/videos/video1.php /video1 [R=301,L]
You can use the following rules in /root/.htaccess
RewriteEngine on
#1--Redirect from "/videos/foo.php" to "/foo"--#
RewriteCond %{THE_REQUEST} /videos/([^.]+)\.php [NC]
RewriteRule ^ /%1 [NE,NC,L,R]
#2--Internally map "/foo" to "/videos/foo.php--#
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/?$ /videos/$1.php [NC,L]
Clear your browser's cache before testin this.
Have you tried
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^yoursite.com
RewriteRule (.*) http://www.yoursite.com/$1 [R=301,L]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /index.html HTTP/
RewriteRule ^index.html$ http://www.yoursite.com/ [R=301,L]
Source:
https://www.branded3.com/blog/htaccess-mod_rewrite-ultimate-guide/
You forgot to add closing $ in your regex.
Please try this:
RewriteEngine On
RewriteRule ^/video1$ /videos/video1.php [QSA,NC,L]
RewriteRule ^/videos/video1.php$ /video1 [R=301,L]
instead of
RewriteEngine On
RewriteRule ^video1 /videos/video1.php [QSA,NC,L]
RewriteRule ^/videos/video1.php /video1 [R=301,L]

Removing a word from our urls

We have the following file structure in our ftp account.
/index.php
/views/account/users/index.php
/views/account/clients/index.php
/views/profile/index.php
/views/settings/index.php
....
Which means that the urls is as follows:
www.thesite.com/
www.thesite.com/views/account/users/
www.thesite.com/views/account/clients/
www.thesite.com/views/profile/
www.thesite.com/views/settings/
...
What we need, is to remove views from all possible variations, so that we can link to, or enter the following url in the browser's address bar.
www.thesite.com/account/users/
Any help would be greatly appreciated.
Try these rules in your site root .htaccess:
RewriteEngine on
RewriteCond %{THE_REQUEST} \s/+views/(\S*)\s [NC]
RewriteRule ^ /%1 [NE,L,R=302]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^((?!views/).+)$ views/$1 [NC,L]
You can use the following Rules in Root/.htaccess :
RewriteEngine on
#/foo to /views/foo
RewriteCond %{THE_REQUEST} /views/([^/.\s]+) [NC]
RewriteRule ^ /%1 [NC,L,R]
RewriteRule ^([^/.]+)/?$ /views/$1 [NC,L]
#Rewrite /foo/bar to /views/foo/bar
RewriteCond %{THE_REQUEST} /views/([^/]+)/([^/.\s]+) [NC]
RewriteRule ^ /%1/%2 [NC,L,R]
RewriteRule ^([^/]+)/([^/.]+)/?$ /views/$1/$2 [NC,

Remove index.php?/name and redirect to /name

I need to redirect the below url
http://localhost/CodeIgniter/index.php?/Welcome/
to
http://localhost/CodeIgniter/Welcome/
and I have tried the below in .htaccess
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /(.*)index\.php($|\ |\?)
RewriteRule ^ /%1 [R=301,L]
The above code taken me to below
http://localhost/CodeIgniter/?/Welcome/
I need to remove that ? mark for avoiding duplicate urls in seo. Can anybody help me
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php?/$1 [L]
And you have to enable mod_rewrite
If you are using PHP version lower than 5.2.6 -> Remove the ? from index.php
You can try your code this way.
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\?/(.*)
RewriteRule ^ /%1? [R=302,L]

htaccess- unable to remove file extension from url php

I am trying the following rules to remove file extension from file name but the problem is it is showing that it is removed but when I login again it is not redirecting to my home page.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase \
RewriteCond %{HTTP_HOST} !^www.example.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/$ $1.php
Thank You
In your redirection just type in page name with no extension, eg. header('Location: index'); or redirect_user('index'); and use the code below in your .htaccess file. now the link on the browser will be say "localhost/index"
RewriteEngine on
RewriteRule ^([^./]{3}[^.]*)$ /index.php?page=$1 [QSA,L]
I think your rules are just a little bit off. You are using THE_REQUEST to redirect php extension to non php extension but you are not using a / after %1 in the rewriterule so when the next rule is read it is not matching because it will only internally redirect if there is a / in that rule. So either add a forward slash after %1 in the second rule or make the backslash optional in the last rule. I would just make it optional in last rule so it will match either way.
Try this update and see how it works.
Options +FollowSymLinks -MultiViews
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www\.example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\ /([^&\ ]+).php [NC]
RewriteRule ^ /%1? [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^([^/]+)/?$ $1.php [NC,L]

Categories