1

i have been trying to make my urls "pretty" / human readable, the urls at the moment are:

[BASE_URL]/?action=viewProposal&proposaltitle=tesst

I want to rewrite them to be just [BASE_URL]/tesst

I tried using the following code and modifying it but it wouldn't work, ie. it didn't redirect the pages but didn't throw any errors.

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{SCRIPT_FILENAME} !-d
RewriteCond %{SCRIPT_FILENAME} !-f

RewriteRule ^users/(\d+)*$ ./profile.php?id=$1
RewriteRule ^threads/(\d+)*$ ./thread.php?id=$1

RewriteRule ^search/(.*)$ ./search.php?query=$1

Will the PHP GET functions still work properly as ?action defined whether its a view / edit / delete?

2
  • Do you want your preety url as /viewProposal/tesst (2 segments) or /tesst ? if it's /tesst then the answer posted bellow should work. Commented Apr 9, 2017 at 15:16
  • @starkeen how would this work if a parameter was an id then a slug for example: /viewpost.php?id=2&slug=$1 Would this redirect urls only if the ID is two? if so how could you make it ignore the ID parameter and set the url as /[slug] Commented Apr 10, 2017 at 18:06

1 Answer 1

1

I am assuming base url your index.php try following rule,

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^([\w-]+)$ index.php?action=viewProposal&proposaltitle=$1 [QSA,L]
Sign up to request clarification or add additional context in comments.

7 Comments

That didnt work mate and its on a base url as in google.co.uk/?action=viewProposal&proposaltitle=tesst
Still there should be some page to handle the values or not? or are you using some framework?
No it is running on index.php but the urls are displaying as just a / then the parameters Its a custom built CMS for proposals, just working on the pretty URL's at the moment. is there any reason it wouldnt have worked? I did access the urls with index.php but they still didnt redirect.
Thanks that worked but it is returning a 404 error now, here is the URL it is producing google.co.uk/viewProposal/viewProposaltesst
Firstly, where are you using the rule why are you showing me the google.co.uk link are you redirecting the page?
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.