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
https://forums.phpfreaks.com/topic/220680-stripping-extension-and-more-from-url/
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

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]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.