Forum Moderators: phranque
hope fully this is the right forum for my question. I want to have a structure like this on my site:
www.mydomain.com/dir1/file1.html
www.mydomain.com/dir2/file1.html
etc.
but dir1, dir2 etc. do NOT exist. I want to make use of mod_rewrite and do this:
www.mydomain.com/dir1/file1.html ==> www.mydomain.com/index.php?id=file1
Can andybody help me or tell me how the code for this must look like?
Thank you so much!
ok I researched for a while now but I did not came up with a solution, yet. Please could anybody give me an example on how to do this?!
So far I have:
RewriteRule ^myfolder/([a-z0-9_-]*)\.html$ /index.php?_id=$1 [NC,L]
The problem with this is that all links, images etc. are incorrect then. For example:
mydomain.com/myfolder/index.php
instead of
mydomain.com/index.php
Any suggestions?
Of course I could edit all Urls of the links and images and make them absolute (e.g. www.mydomain.com/index.php) but doesn't that look "bad" for Google Spider? Also, I would have to change hundreds of links ...
Defining exactly how it is going to work takes longer than writing the code to actually make it work.
The problem you are seeing is that relative links are resolved by the browser and are treated as being relative to the URL that is shown in the browser URL bar.
Page URLs are defined by what URL is in the link that someone clicks on. If you need a new URL, then that link must be edited. I use links that start with a / and so are fixed relative to the root of the site.
Of course I could edit all Urls of the links and images and make them absolute (e.g. www.mydomain.com/index.php) but doesn't that look "bad" for Google Spider? Also, I would have to change hundreds of links ...
Remember, it is the client (e.g. browser) which resolves relative links, and the browser thinks it is accessing a page in /myfolder and will therefore resolve all page-relative links based on the /myfolder location.
The other alternative is to add a rule to internally rewrite requests for all images, CSS, external JS files, etc. from "/myfolder" back to "/".
Jim