1

I have urls that look like http://WEBSITE.com/?page_id=53?&nid=3104&lid=3100

As you can guess it is an ugly wordpress site, search function pulling up a result with id nid=3104 and lid=3100 . Both numbers are necessary.

I would rather URLs look like http://WEBSITE.com/Chicago-Shelter-name or http://WEBSITE.com/shelter/Chicago-Shelter-name

How can I get an .htaccess file to read the search result from a PHP script (that will pull if from SQL using the NID and LID numbers) and when the name comes back as "Chicago Shelter name" rewrite the url http://WEBSITE.com/Chicago-Shelter-name

4
  • No need to Apache rewrite http://WEBSITE.com/?page_id=53?&nid=3104&lid=3100, simply catch that in your index.php file and redirect the user with a "301 Moved Permanently" to the pretty URL'd page. Commented Mar 29, 2015 at 19:56
  • I believe the good looking URLs are not working yet, so 301 redirects are not an option, am I right? Commented Mar 29, 2015 at 20:42
  • My index.php file has nothing to do with this. It is wordpress, so some other page called "?page_id=53" is running the search for nid=3104&lid=3100 I would like the URL to read human readable text as explained above. How is a 301 redirect going to help when that changes to a different webpage. Commented Mar 30, 2015 at 5:57
  • I would like to display the contents of WEBSITE.com/?page_id=53?&nid=3104&lid=3100 while showing the fake URL WEBSITE.com/shelter/Chicago-Shelter-name My understanding is that .htaccess Mod rewrite is required. I confirmed it working on a blank page, but not my wordpress page_id=53 Commented Mar 30, 2015 at 5:59

1 Answer 1

1

SOLVED

Not easy. .htaccess needs:

<IfModule mod_rewrite.c>
  RewriteEngine on
  
  RewriteRule    ^custom/name/?$  newfile.php?nid=3104&lid=3100    [NC,L]
  
</IfModule>

This being wordpress required a replica page of the entire search result. The menu and sidebar will not reflect any updates, but I had to break out of wordpress. Copied the source of the search result, removed the result, added the PHP that displays the result. All inside of "newfile.php"

The above .htaccess file works. If http://WEBSITE.com/custom/name" is entered, it will display that entered URL but in reality secretly display the result of "http://WEBSITE.com/newfile.php?nid=3104&lid=3100"

This is what I wanted. Not the best, and now I must create lines of code for every single possible item in search. But it works.

Sign up to request clarification or add additional context in comments.

Comments

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.