I've looked around and my web knowledge is basic. I'm trying to make a dynamic URL link to another-- that is, where one part of the URL can be different.
In this case, I'm trying to make (With my URL scrubbed to some generic one as not to break any rules, here):
https://theurl.com/news/fullnews.php?fn_id=33
TO
https://www.theurl.com/index.php?fn_mode=fullnews&fn_id=33
Where the 33 is a number that can be different based on the article linked.
Thanks any help that can be provided! I've tried editing some similar scripts but seem to not know quite what I'm doing.
This probably is what you are looking for:
RewriteEngine on
RewriteCond %{QUERY_STRING} ^fn_id=(\d+)$
RewriteRule ^/?news/fullnews\.php$ /index.php?fn_mode=fullnews&fn_id=%1 [END]
You need to enable the interpretation of distributed configuration files (".htaccess") for this and obviously the rewriting module needs to be loaded and enabled in the http server.
Much more elegant and preferred for SEO reasons however would be to use a URL like that:
https://example.com/fullnews/33 or https://example.com/news/33
Which could be achieved by those rewriting rules:
RewriteEngine on
RewriteRule ^/?fullnews/(\d+)$ /index.php?fn_mode=fullnews&fn_id=$1 [END]
I tried reversing the two current rules and still the same result. The other rule there that redirects urls to https instead of http works fine.
Of course you cn easily format your code, everyone else succeeds, you will too. Just use the buttons over the editor: mark your code block as exactly that: code block. That's it. External resources like pastebins or whatever are not accepted here for good reasons. That is documented.
Sorry, of course the regular patterns should start with
^/?...
and not^?/...
. You will not get around reading a bit about regular expressions. It is one of the most commonly used tool for programming. Especially for string processing.Yeah I've been reading up as best I can using regexone.com. That being said, the fixed code!... kind of... works. The & is decoded to %26 and it needs the & to work correctly. Trying to fix this now. Hrm....
Fixed it! Changed the [END] to an [R,L], under someone else's advisement. Seems to work great now. :)