Jump to content

Recommended Posts

So I have the below code doing two things. The first part removing .php extension from urls and the second part redirecting from a clean url to the original. Its the second part of this that is not working and I dont know why and am hoping and praying someone here can help with this. I have tried many different tutorials with different approaches and still no luck. Below is the most basic of the attempts I have tried and from what I can tell it SHOULD work, but alas...

Anyway its trying to get the clean url example.com/post/2 to redirect to example.com/post.php?id=2

Please help!

 

RewriteEngine On

#remove .php extension
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteCond %{REQUEST_URI} !/$
RewriteRule (.*) $1\.php [L]

#redirect
RewriteRule ^/post/([0-9]+)$ /post.php?id=$1

Link to comment
https://forums.phpfreaks.com/topic/272495-clean-url-attempt-fail/
Share on other sites

That'll only redirect for requests that have a path starting with update. This could imply you're going to define every possible URL you have and redirect it?

 

Why not redirect the whole thing and have PHP determine what content to serve up.

 

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [QSA,L]
</IfModule>

Edited by CPD
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.