how to remove id of div in url with htaccess - .htaccess

I am having in an url the id of a div (#latest) like this at the end:
http://example.com/discussion/64/moderators-only#latest
http://example.com/discussion/32/bugs#latest
// and so on...
How can i remove the #latest in all these url's with htaccess?

You can't. Anything after the # is a URL fragment that the browser never even sends to the server. So the only thing the webserver sees is: http://example.com/discussion/64/moderators-only. So nothing in the htaccess or even in the apache config can do anything about those fragments.
You'll need to employ some sort of javascript or client-side solution if you want to remove it. But a better question is, do you need this in order to display the content correctly? If so, then how do you expect to display the content if this is gone?

Related

Odd URL RewriteRule Behaviour

Hoping someone with better experience can guide me on this.
Ref: https://www.donbur.co.uk/gb-en/news/index.php
This is a dynamically generated news summary list with a button link to article pages. Until last week, the button links worked fine.
Each link calls a URL
<a class="button" href="https://www.donbur.co.uk/news/<?php echo rawurlencode($row_newsResult['newsurlkey']);?>">Read full article</a>
This parses fine.
To process this link, I've then got an htaccess RewriteRule:
RewriteRule ^news/([^/]*)$ /gb-en/news/article.php?title=$1 [L]
The article.php file then uses the unique title to identify and show the full article.... or at least that's what it should do and has done.
For whatever reason, from the news index.php page, when the link is clicked, it just refreshes the page and re-writes the URL to
https://www.donbur.co.uk/gb-en/news/index.php/[uniquetitleparameter]?title=[uniquetitleparameter]
The parts in brackets [] obviously get populated with the rawurlencoded string.
I cannot for the life of me understand what is happening here - especially when I have a similar page, doing a very similar thing, works absolutely fine (https://www.donbur.co.uk/gb-en/features/feature-list.php)!!!!
This all started going wrong when I converted the site from http to https: but can't work out if that's relevant??
Turns out this was just a bad caching issue. Temporarily disabled cache as suggested and all works well.

Is there a way to not require a favicon?

Is there a way, to take out the HTML link and provide a favicon or alternatively, not let it be requested - perhaps using .htaccess?
<link rel=icon href=icon>
For instance, when a user opens a [.pdf] or otherwise, there is no icon - displaying 'nothing' or at least it is transparent. The purpose, is to minimise the number of HTTP requests. You see, I do not want to have [the HTML link] at all - so a data URI is not necessarily an option. In other words, I wish to remove this HTML tag - displaying nothing like a [.pdf] file, in the browser.
If you don't have a tag specifying the url of a favicon, most browsers will just send a blind request to www.yourdomain.com/favicon.ico and hope for the best (thanks to w3d for pointing this out). This isn't something you can prevent them from doing.
Although, from what I know, favicons are cached in the clients browser, so they won't even be sending requests for it on every page-load.

ModX redirect based on query string (Revolution 2.3)

I am rebuilding a website in ModX and I want to redirect the old URLs to the new ModX pages, automatically.
An old URL is of the form, http://www.oldsite.com/?pg=2
Every page is like this, so I need to manually map the old page IDs to the new ModX resource IDs. For example, pg=2 is the contact page, which is now resource ID 11, so I'll end up with a map like [2=>11, 3=>15, etc]
If I tweak the main index.php right in the docroot, this does exactly what I want:
/* execute the request handler */
if (!MODX_API_MODE) {
if (isset($_GET["pg"])) {
if ($_GET["pg"] == 2) {
$url = $url = $modx->makeUrl(11);
$modx->sendRedirect($url);
}
else {
// Page is set, but we don't have a redirect for it.
$modx->handleRequest();
}
}
else {
$modx->handleRequest();
}
}
However, I am not happy with hacking index.php directly. I'm a bit short of ModX experience to know exactly where to put this code. I tried:
A snippet, which I then called from my HTML header before any HTML, but the redirect stopped working
The Redirector extra, but this doesn't work on the QUERY_STRING, I don't think
Any insight is appreciated, for the best place to package this code, or a pointer towards an Extra I should be using.
The solution that worked for me, following Sean's insights below, is a plugin. The plugin code is below. For other plugin newbies like me, ensure you visit the "System Events" tab to enable your plugin for the event you're trying to access.
<?php
if ($modx->event->name == 'OnWebPageInit') {
// Look to see if the GET params include a pg. If they do, we have a request
// for one of the old pages.
if (isset($_GET["pg"])) {
// Map the old pg IDs to the new resource IDs.
if ($_GET["pg"] == 2) {
$url = $modx->makeUrl(11);
}
// Add more here...
// When done trying to match, redirect.
// But only do the redirect if we found a URL.
if (isset($url)) {
$modx->sendRedirect($url, array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
exit;
}
}
}
My preference to do this is in the .htaccess file with redirects or url rewriting - that way you can send the redirect and the response code ~before~ modx has to process anything [save a bit of overhead]
if you still want to do this in modx, take a peek at the sendRedirect docs & send the correct response code [so google gets the hint that the page has actually moved] Note: the $responseCode option is depreciated and you should use it in the options array these days:
$modx->sendRedirect('http://modx.com',array('responseCode' => 'HTTP/1.1 301 Moved Permanently'));
I do agree with not hacking the index.php file, only will cause you grief. What you want to do is place your redirect code in a plugin. Check the Modx API docs for the appropriate event for it to fire on - perhaps: OnWebPageInit will do the trick. Sorry, I don't know exactly which one will work.
HOWEVER ~ IMPORTANT NOTE!
Not all events are actually active, they may show up in the modx manager but don't actually do anything, you will just have to test or dig through the code to find out. [or ask in the community] Again, sorry, I don;t know for sure which ones work and which don't.

Redirect parent not childs htaccess

In my magento module there is an extension.
Some urls like
http://www.domain.com/abc/p#abcs.html
http://www.domain.com/abc/p#xyz.html
etc
But when browsing http://www.domain.com/abc/p -> lead to blank page
I do not need http://www.domain.com/abc/p url
Is anybody help me
I want to redirect the url http://www.domain.com/abc/p to 404 page
without affecting its childs
ie
1. http://www.domain.com/abc/p#abcs.html
2. http://www.domain.com/abc/p#xyz.html
Points to its current position and
http://www.domain.com/abc/p to 404
Any help apperciated
Based on your comment it seems http://www.domain.com/abc/p#abcs.html shows proper content but http://www.domain.com/abc/p shows blank page.
In that case you can't do that via .htaccess because on server side URL will always be: http://www.domain.com/abc/p.
You need to put some custom Javascript in your page and redirect to some non-existant page (resulting in 404) by checking location.href using your Javascript.

How to remove bits from the url using the htaccess file?

Hi I am using joomla for my website and I would like to remove the bits in between my url.
The original URL:
"/calums/index.php/component/jsjobs/jsjobs/employer/"
The way I want it to be:
"/calums/employer/"
It would be great if some one can help me work out how to do it using the htaccess file.
Thanks.
first of all you need to enable SEF in Joomla to get rid of the /index.php/ part:
enable sef in global configuration (the first two checkboxes)
copy your htaccess.txt to .htaccess
This is transparent and should make your URL look like this:
/calums/component/jsjobs/jsjobs/employer/
Then, by looking at your URL, it appears the component jsjobs doesn't have a menu item associated. Menu items are associated with views, so you should go into menu manager and add a new menu item and try to setup menu items for jsjobs. You might not find one that matches exactly but you should be partway there.
Once a menu item is setup (and the cache is cleared) you should begin to see
/component/jsjobs replaced at a minimum. If there is no menu item that produces the right url, then you might have to create an .xml file in the component/view folder you desire. More details in this answer: Joomla Developement :: Probleme with URL Rewriting
my first answer on stackoverflow. try this:
RewriteEngine on
RewriteRule ^(\w)/(\w)/(.*) $1/index.php/component/jsjobs/jsjobs/$2/$3

Resources