Jump to content
MakeWebGames

.htaccess


Recommended Posts

Hello, i'm playing around with the .htaccess file.

I've got this

 

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

 

Which does this to links:

http://www.example.com/usersonline.php

to

http://www.example.com/usersonline

Is there a way in the .htaccess file to make all pages display like the above link without editing every link on the site?

Link to comment
Share on other sites

Hello, i'm playing around with the .htaccess file.

I've got this

 

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [NC,L]

 

Which does this to links:

http://www.example.com/usersonline.php

to

http://www.example.com/usersonline

Is there a way in the .htaccess file to make all pages display like the above link without editing every link on the site?

This won't take into account variables in the URL.

Link to comment
Share on other sites

If done right in htaccess it won't matter if you have the file extension in the links itself. I believe like what [MENTION=70137]john.[/MENTION] said about a permanent redirect will do just that, it will redirect to the re-written URL to match your regex pattern.

I'm assuming you'd use a HTTP302 and this is okay for the shortrun but longterm you'd want to edit links, this is why mccodes needs a url dispatcher

Link to comment
Share on other sites

Are you trying to rewrite all of your ?'s and &'s? If so your looking at a lot of work. You need to include in your regex all of your query string keys.

Or or you can look how wordpress does it but your still looking at a lot of work but since they use a standard they get by fairly easy by doing it with PHP

I'm not too savvy with Apache so don't take my word for it

Link to comment
Share on other sites

well so far the ? is still there like so

viewuser?u=1 instead of viewuser.php?u=1.

i dont mind the ?u=1.

i just though it would of been easier to use .htaccess to change the link looks instead of going through each page (which will takes for ages)

Link to comment
Share on other sites

Why not have it parse the first bit to the file and after the / you could parse that as a query string...

so /user/view/john would get translated into user.php?query=view/john

and you can then parse the querystring through a bunch of code that gets the true values

Link to comment
Share on other sites

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.   Paste as plain text instead

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