user1032854
user1032854

Reputation: 95

Ignore last string in URL after the last slash

for example: when a user types in www.website.com/site/blue, I want them to go to www.website.com/site/index.php in the web browser. The reason for this is that I want to use php to grab blue from the URL and place it in www.website.com/site/index.php

So when someone types in www.website.com/site/blue ... they should see "Hello blue!!!" in www.website.com/site/index.php

Upvotes: 0

Views: 738

Answers (3)

rechie
rechie

Reputation: 2209

try this htaccess config:

RewriteEngine on
RewriteCond $1 !^(index\.php|resources|robots\.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]

Upvotes: 0

dpk2442
dpk2442

Reputation: 701

It sounds like you need to use an htaccess file and Apache's mod_rewrite. If you are allowed to do this on your server, make a file called .htaccess in the site directory.

RewriteEngine on
RewriteRule ^(.*)$ index.php?color=$1

That will rewrite every request as a query string to index.php for you to parse.

Upvotes: 2

tgarv
tgarv

Reputation: 216

Basically, you can split the page URL at the "/" and it will give you an array of parts of the URL. The last of these parts will be "blue" in your example. Try something like the following:

var parts = document.URL.split("/");
var foo = parts.pop();
var url = parts.join("/") + "/index.php";
window.location.href = url;

And then the variable foo is the variable "blue" that you're looking for.

Upvotes: 0

Related Questions