Jump to content

stripping extension (and more) from url


fortnox007

Recommended Posts

Hi all,

 

I just managed to make a little mod_rewrite rule which manages to interpret url's without the extension and calls the right file with the extension (ie. /articles  calls  articles.php) . But now i am left with another question which i am almost certain has nothing to do with mod_rewrite, but rather with a php trick.

 

In case someone enters on my site  www.mydomain.com/laalalalala.php

How do i get rid of that last part(the extension for example)? Do i maybe have to get the GET['var'] and run it through a regex and reload the page with the stripped version?

 

That was all i could think off but it sound so complicated.

if anyone has an idea i would love to hear it :)

cheers! ::)

 

P.s.s if anyone want's that rewrite rule, let me know. I saw quite some people on the internet looking for it ::)

Link to comment
Share on other sites

isnt hat a mod rewrite question?

Well mod rewrite should be able to handle that without much problem anyhow

hmm, you might be right sorry if this is in the wrong forum than  :(

 

Just to make sure i am,.. i want to visually change the address in the browser of the visitor.

sorry again if i misplaced it

 

i have this in my htaccess but its not changing anything(visibly), that's why i thought to reload the page with by using getvariables

RewriteRule ^([a-zA-Z0-9]+)(/.*)?$ /$1\.php$2

Link to comment
Share on other sites

By default mod_rewrite will do it invisibly. If you want to actually redirect the browser then add the [R] flag.

 

Like

RewriteCond %{REQUEST_FILENAME} -f
RewriteRule (^|/)([^/]+)\.php$ $1 [R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^ %{REQUEST_FILENAME}.php [L]

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.