Shinyshell Community Forums > Coding >
Rewriting URLs.


[1]


August 15 02009, 19:33 GMT
Sir Aaron
(~Wake Me Up Inside~)

Sir Aaron's avatar
Location: USA
Post count: 10
us
Hey, I haven't really posted here in a while.. I never stopped looking at the forum though.

Anyway, recently I've switched my site to a PHP template engine, and my URLs are all now ?page=page. I was wondering, how I might rewrite the URL's to have no extension. I tried a few times, modifying other ones I saw, but they all don't work. Any ideas?

Thanks!

August 17 02009, 08:59 GMT
lec**
Supra stultitiam

lec's avatar
Location: Varaždin, Croatia
Post count: 173
hr
To get rid of the extension, I use:

 RewriteEngine On
 
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteCond %{REQUEST_FILENAME}.php -f
 RewriteRule ^([A-Za-z0-9_-]+)?$ $1.php [L,QSA]
 
RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([A-Za-z0-9_-]+)?$ $1.php [L,QSA]
]]>


Let me know how it goes.

August 18 02009, 03:22 GMT
Sir Aaron
(~Wake Me Up Inside~)

Sir Aaron's avatar
Location: USA
Post count: 10
us
Oh, sorry, I worded my post wrong. I meant, I would like to rewrite the /index.php?page=about to /about.

Anyway, though I used to use that code before, and it worked, right now isn't working at all..

August 24 02009, 19:58 GMT
lec**
Supra stultitiam

lec's avatar
Location: Varaždin, Croatia
Post count: 173
hr
Oh dear, okay... I'm sorry for making you wait a week, for some reason I thought I'd resolved this... :(

This should do what you're looking for:
 RewriteEngine On
 
 # a url that doesn't identify a file or
 # directory that exists will be rewritten
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule ^(.*?)/? index.php?page=$1
 
RewriteEngine On

# a url that doesn't identify a file or
# directory that exists will be rewritten
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*?)/? index.php?page=$1
]]>

August 25 02009, 21:50 GMT
Sir Aaron
(~Wake Me Up Inside~)

Sir Aaron's avatar
Location: USA
Post count: 10
us
Haha, it's okay.

And oh, that doesn't work either...>_>. I think something is wrong with my site..nothing's really working. Is there a way to see if Apache/ .htaccess is working alright?

August 28 02009, 05:11 GMT
SpaceMan
Member

SpaceMan's avatar
Location: Earth
Post count: 32
ca
The server will react with 500 Internal Server Error when the .htaccess has errors, so intentionally write a wrong .htaccess and see what happens.

Maybe you can't do www.example.com/PageName, but you can do www.example.com/p/PageName

RewriteEngine On
 RewriteRule ^p\/([^\/]+)$ index.php?page=$1
RewriteRule ^p\/([^\/]+)$ index.php?page=$1]]>

August 28 02009, 13:54 GMT
Sir Aaron
(~Wake Me Up Inside~)

Sir Aaron's avatar
Location: USA
Post count: 10
us
And that doesn't work either. It turns up a 404 error.


[1]



Forum Information
  Currently Active Members [detailed] (0 members and ? guests)
-
Forum Statistics
Topics: 0, Posts: 0, Members: 108.
Welcome to our newest member, adamthephantump
Most members online was 5, on August 28 2009, at 21:49:28.
Legend
    Forums with unread topics in them are indicated by a strong yellow colouring around the forum icon.
    Forums with no unread topics have the standard pale yellow colouring around the forum icon.
    Forums with a blue arrow icon will redirect you to a non-forum page.
    Locked forums have a little padlock by their icon. You won't be able to post in these forums.
Shinyshell Home | Contact | Staff List | Archive | Top 

Conventional Login

Don't have an account? You may want to create one.

OpenID Login
OpenID login and registration is usable, but not finished.
What is OpenID?
Search

(advanced search)
Site Stats
  Total members: 108
  Latest member: adamthephantump
  Members currently online: 0
  Most online: 5 - Aug 28, 2009 (21:49)
  Front page hits: 87998
Developer info
  Site version: 3.5 Alpha
  16 queries - 9 templates
Under the Spotlight
Collide Site
Collide make fabulously dreamy electronic-industrial music, they're one of my favourite bands! Give them a chance to take control of your life - myspace | youtube - "Euphoria".

Collide Site - Hits: 4597

5/5 (2) | Rate this site?