Redirecting and rewritting multiple urls with htaccess

I am trying to redirect and rewrite the following urls but in some cases I want to preserve some values but hide from the url. Here is the example of what I want to get:

I have this URLs:

  • etc
  • etc

And I want to get this urls:

  • etc
  • etc

I have this code, the first two examples work well but for the example with orange don´t work:

<IfModule mod_rewrite.c> RewriteEngine on RewriteBase / RewriteCond %{THE_REQUEST} /\?a=orange&b=([^\s&]+)&c=([^\s&]+)&d=([^\s&]+) [NC] RewriteRule ^ /orange/%3/? [R=302,L,NE] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^/orange/([^/.]+)/?$ ?a=orange&b=%1&c=%2&d=([^\s&]+) [L,QSA] RewriteCond %{THE_REQUEST} /\?a=([^\s&]+) [NC] RewriteRule ^ /%1/? [R=302,L,NE] RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^([^/.]+)/?$ ?a=$1 [L,QSA] </IfModule>


You can Try this :

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s/\?a=([^&]+)&b=([^&]+)&c=([^&]+)&d=([^&\s]+) [NC]
RewriteRule ^ /%1/%4? [R,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*?)/(.*?)/?$ /?a=$1&d=$2 [QSA,NC,L]

I have resolved my problem migrating my "spaghetti code" to a Laravel framework, and using the file routes.php to pass the variables and blade templates for minimizing the use of this variables.

Category:php Time:2018-12-02 Views:1

Related post

  • Redirect using username in URL with .htaccess 2011-07-28

    I want to do a redirection where a user enters their user name in the URL and redirects to their profile, like this-> redirects and obviously shows their profile. I've looked around on

  • Redirecting to the clean URL with .htaccess 2015-09-28

    I imagine this is a problem with a fairly simple solution to anyone who's proficient with the syntax of .htaccess files, but unfortunately that I am not. I've worked out how to make it so that when someone accesses then interna

  • Rewrite a url with .htaccess 2010-12-19

    I have page I created witch display's topics by there ID in the database. It is topic.php?id=35 which would go to a topic. I want to rewrite that with .htaccess to /topics/id/IDNUMBERHERE Any ideas how I could go about it? --------------Solutions----

  • rewrite friendly url with .htaccess issue 2011-11-13

    I want to make Friendly URLs, but when I try my PHP code works correctly but my CSS and JS files are not loaded correctly. It tries to get these files from different path. I'm using WAMP, and I've created bsp directory for my project. There are two f

  • Redirect and rewrite the URL via mod_rewrite 2012-01-31

    My anchor is like this <a href="http://localhost/haveg/employer?id=7003&title=the-message-title">employer</a> And when i click the anchor i want to reach here http://localhost/haveg/employer/7003/the-message-title so far i have writte

  • How to successfully Rewrite a URL with .htaccess 2010-03-28

    I am trying to rewrite to so that it will show up in the location bar as "broadcasts" but actually go to /feed. Here is what I have in the .htaccess file: <IfModule mod_rewrite.c> RewriteEngine on RewriteRu

  • htaccess redirect then rewrite a url to make it pretty 2013-12-03

    I currently have the url because that is where the file is actually found: I redirect a nicer url to the above url with a 301. redirect 301 /niceee so now when people

  • How do I rewrite a POST request from a form to a user-friendly URL with htaccess? 2011-12-20

    As the topic - How do I rewrite a POST request from a form to a user-friendly URL with htaccess? The scenario: I have a webpage that uses a search-form. When I submit that form using method="post" it works flawlessly. BUT I don't get any text in the

  • rewrite my url using htaccess 2011-06-24

    I am working in codeigniter project I want to rewrite my URL using htaccess. I have a URL like and I want to change it to I just remove the " main " . how can I achieved it . Sorry for bad English :( --------------Solut

  • Rewriting form urls with javascript 2011-04-28

    Search forms go to ugly urls normally. If I want users to see nice urls I need to rewrite them on server side and http redirect them. I'd like to avoid this round trip and rewrite this urls by some simple javascript code. (without javascript on you'l

  • Best way to rewrite an url with a varying number of parameters 2011-11-05

    What is the best way to rewrite an url with a varying number of parameters? For example I can have something like this: followed by followed by follo

  • making clean url with htaccess 2012-03-21

    I am trying to make clean url with htaccess I have a profile.php page and I get user domain name to display his page now if the user for example hit I will display his main page it is equivalent to

  • Rewrite an url with %23 to # 2012-03-29

    I've tried to do a bit of searching (and come up with this: How to rewrite a URL with %23 in it?) but its not quite what I'm looking for. I have a website, with a tabbed content section (x-tab, y-tab, z-tab etc.). There are links:

  • How to remove a directory from URL with .htaccess..? 2010-11-25

    Ok, I've read so many examples on so many sites, it gets really hard to understand what's going on when it seems there are dozens of way to do anything with .htaccess. Anyway, here's my setup: I have 2 domain names and examp

  • Finding and replacing multiple words with different words 2013-05-09

    I have a document with a lot of diacritical marks. Is there a way I can replace and/or remove these at one time? I've tried autocorrect and find and replace but none of these work. --------------Solutions------------- See

  • Hiding file extensions and forcing redirecting to extensionless URL with .htaccess 2012-02-05

    I am trying to use .htaccess to rewrite URLs and remove extensions .htm, .php and .html from URLs and force redirecting when pages are requested with their extensions so that: will get redirected to

  • How to make a better URL with .htaccess and multiple parameters? 2010-04-23

    I have a very long a unfriendly URL an I'm looking to make SEO better for the site: I would like to have this instead: http:// all the URLS ar

  • Rewriting multiple URL in the same depth with htaccess 2012-01-10

    I lately started to use htaccess to rewrite my URL's but i've got some trouble with it. Im not sure if URL depth is the right name in english, but i don't know how to define what URL links to wich page with the same URL depth. For example, I've got t

  • Redirecting a large number of URLs with htaccess or php header 2010-04-08

    I have undergone a major website overhaul and now have 5,000+ incoming links from search engines and external sites, bookmark services etc that lead to dead pages or 404 errors. A lot of the pages have corresponding "permalinks" or known replacement

Copyright (C), All Rights Reserved.

processed in 6.515 (s). 15 q(s)