MOTIVECODEX
MOTIVECODEX

Reputation: 2752

Changing URL PHP jQuery or mod_rewrite

I have XAMPP installed, I run everything on my localhost/ So imagine I have localhost/website/index.php or www.website.com/index.php;

How can I delete index.php and/or replace it with something like; localhost/website/:) or www.website.com/:)

or show it like; localhost/website or www.website.com

Example;

$URLcapture = $_SERVER['PHP_SELF'];
$URLcustom = ":)";

$_SERVER['PHP_SELF'] = $URLcustom;
echo $_SERVER['PHP_SELF'];

This shows :) of course but how can I get :) in my URL?

Thank you, F4LLCON

EDIT

Under loaded modules I can see mod_rewrite.

STEPS BEFORE EVERYTHING -- START - In httpd.conf I've deleted;

# from infront of LoadModule rewrite_module modules/mod_rewrite. 

Changed;

<Directory />
    Options FollowSymLinks
    AllowOverride All
    Order deny,allow
    Deny from all
</Directory> 

and

<Directory "C:/xampp/cgi-bin">
    AllowOverride All
    Options +FollowSymLinks
    Order allow,deny
    Allow from all
</Directory>

STEPS BEFORE EVERYTHING -- END -

In .htaccess I've added

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ index.php?/$1 [L]

and also tried

RewriteEngine On
RewriteBase /
RewriteRule index.php nieuw.php

What am I doing wrong?

EDIT 2

Not touching .htaccess at all worked. 1. Closed xampp and apache.

  1. Edited httpd.conf in C:\xampp\apache\conf;

2a Start with above steps;

2a STEPS BEFORE EVERYTHING -- START - till

2a STEPS BEFORE EVERYTHING -- END -

2b. added at the end of http.conf;

<IfModule mod_rewrite.c>  
RewriteEngine on  
RewriteRule ^/home$ /spiderweb/Web-projects/Web-stage/Nieuwidw/index.php 
RewriteRule ^/link$ /spiderweb/Web-projects/Web-stage/Nieuwidw/link.php 
RewriteRule ^/contact$ /spiderweb/Web-projects/Web-stage/Nieuwidw/contact.html
RewriteRule ^/about$ /spiderweb/Web-projects/Web-stage/Nieuwidw/about.html
</IfModule>
  1. start xampp/apache and type localhost/home

3a. the website will open but the layout is not there. So it does not load style.css

3b. .css is in;

3b. C:\xampp\htdocs\spiderweb\Web-projects\Web-stage\Nieuwidw\includes

3c. images are in;

3c. C:\xampp\htdocs\spiderweb\Web-projects\Web-stage\Nieuwidw\includes\images

Next

  1. on home you can see "more" button under every product, if you press on more you will be redirected to the products page in link.php but every product gets it's own ID in the URL;

4a. http://localhost/link.php?id=126 so the page shows up; not found because the URL is different

How to fix these problems?

Upvotes: 2

Views: 614

Answers (2)

TeChn4K
TeChn4K

Reputation: 2405

In php :

header("Location: http://www.example.com/");

But the best way is using htaccess (like ManseUK says)

Upvotes: 2

Manse
Manse

Reputation: 38147

If you are able to the best way of doing this is using mod_rewrite - you then include a rule like the one below and the index.php is hidden

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]

Upvotes: 1

Related Questions