OK, so I have this problem that I can’t figure out how to solve after searching around online for some time. I apologize for the length here but this will require a little explanation before I can ask my question. I have a website with a page structure that looks something like this basically:
http://www.mywebsite.com/directory/subdirectory/page1.php
http://www.mywebsite.com/directory/subdirectory/page2.php
http://www.mywebsite.com/directory/subdirectory/page3.php
…
etc
The problem is I’ve found that this doesn’t seem to be very SEO friendly. Pages that are contained within the subdirectory do not get picked up by Google crawlers by the looks of it, but pages only one directory removed such as this:
http://www.mywebsite.com/directory/page.php
…pick up in Google search results just fine right on the front page. But I need those pages in the subdirectories to be picked up too because they are where I can expect to gain the bulk of my traffic.
The simplest solution to this of course would be to merely reorganize my tree structure such that none of my files are more than one directory removed from the root. But for a number of reasons this isn’t really an option because it would be a technical nightmare for me to reorganize some 1800+ files and 60+ folders on my site to adapt to the new structure, not to mention even if I did it would no longer be as elegantly organized due to my lack of ability to use subdirectories.
So ideally what I would like to do (and from what I’ve seen others do), is apparently you can use Apache functions like mod_rewrite to change the path of the file in your browser while still retaining the tree structure you originally had in your FTP server.
So this: http://www.mywebsite.com/directory/subdirectory/page1.php
Becomes this: http://www.mywebsite.com/new-page-url/
But ONLY in your web browser, not in the actual FTP trees. Thus, I retain my organization structure, but Google picks up the pages as something important because they don’t appear to be buried in subdirectories.
My issue is mod_rewrite looks really confusing and unruly to use, and I don’t quite know how the code should look like in my htaccess. Ideally I would like to generate the page URL based on a variable I defined on the page in PHP. For example: if I have the variable $title = “spider-man”; on the page, I want mod_rewrite to detect this variable and then spit it out as the new page title, such that:
This: http://www.mywebsite.com/directory/subdirectory/page1.php
Becomes this: http://www.mywebsite.com/spider-man/
But I’ve never seen any tutorials or explanations online that show how to implement this specific usage of it. So, is this possible, or can mod_rewrite not pick up PHP variables that are defined inside the page? And if it is possible, what should my code look like?