php - How to redirect everything after slash to domain before?


Question: 

This is what I'm trying to do:

I want example.com/car/{whatever} redirected to example.com/{whatever}.

For example, example.com/car/honda should be redirected to example.com/honda

BUT if there is nothing after /car/, then just leave it as that.

How can i do that in .htaccess ?




1 Answer: 

Removing a prefix from a URL is pretty simple, just

RewriteRule ^car/(.*)$ /$1 [R,L]

In order to keep a special case, you must put it in front

RewriteRule ^car/$ - [L]

This rule says, if there is just car/ leave it alone, see RewriteRule substitution.

 

More Articles


node.js - Can't run NPM or ng build, or Apache in Ubuntu terminal

This question already has an answer here: env: bash\r: No such file or directory 4 answers Error with gradlew: /usr/bin/env: bash: No such file or directory 3 answe

php - MySql Install on Ubuntu root issue

Setting. I'm running Ubuntu 15.04 on a custom machine with an existing PHP / Apache / Sqlite setup. I recently installed MySql to fiddle around with Laravel a bit. It was working perfectly until I wasn't paying attention and did something incredibly stupid. I intended to export all of the user's

shell - Change the Particualy string value without string comparison in a file using Command line Ubuntu

I want to create a shell script to change the string values which is after '=' in my file Using command line.File is like: String name = "Max"; String age = "24"; String address = "Noida";OrString name=MaxString age=24String address=NoidaBut here, I don't wanna string comparison, Like this:$ sed -i


bash - How does the keyword “if” test if a value is true or false?

In bash scriptif [ 1 ]then echo "Yes"else echo "No"fiOutput: YesIt represents that '1' is treated as true value.But in code:word = Linuxletter = nuxiif echo "$word" | grep -q "$letter"then echo "Yes"else echo "No"fiOutput: NoBut echo "$word" | grep -q "$letter" will return 1, so why is the

linux - diff command to get number of different lines only

Can I use the diff command to find out if two of files differ by k lines?I don't want the contextual difference, just the total number of lines that are different between two files. Best if the result is just a single integer.

node.js - Querying multiple sensors regularly using NodeJS

I need to fetch the values of about 200 sensors every 15 seconds or so. To fetch the values I simply need to make an HTTP call with basic authentication and parse the response. The catch is that these sensors might be on slow connection so I need to wait at least 5 seconds for one sensor (but usuall


Shell script - convert Excel (xlsx) to CSV - remove blank space / tab space

I receive excel file (xslx) with multiple sheets for my project. The number of records on these sheets ranges from 15k to 70k per sheet. I need to perform following tasks on this data and then convert it to CSV. Or covert to CSV and then process the data either way its fine.Input Example:call_no un

mysql - Apache2 / phpmyadmin - PHP isn't working

I was working on a project of mine . then i had to restart the computer.Once I did suddenly PHP stopped working on Apache. then i starting looking into the configuration files and error logs and fixed a spelling error in the config file, but STILL the problem persisted, then i decided to re-install

Why does the following code raise a SegFault. c(Linux)

This a code that would reverse the data of a document and save it in the same document itself.However I am getting a Segmentation Fault.Please Help,I don't know why it gives a SegFault.#include <stdio.h>#include <stdlib.h>#include <termios.h>#include <fcntl.h>#include <str

shell - monitor for file then copy to another directory

I'm relatively new to unix scripting, so apologies for the newbie question.I need to create a script which will permanently run in the background, and monitor for a file to arrive in an FTP landing directory, then copy it to a different directory, and lastly remove the file from the original directo